Created
January 27, 2017 20:00
-
-
Save efuller/19805567d07f1704c88d93017310588e to your computer and use it in GitHub Desktop.
List WordPress pages using a template.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// source: https://paulund.co.uk/list-pages-using-page-template | |
$args = array( | |
'post_type' => 'page', | |
'meta_key' => '_wp_page_template', | |
'meta_value' => 'template-two-column-page.php', // the template you want to check | |
); | |
$page_template_query = new WP_Query( $args ); | |
if ( ! empty( $page_template_query->posts ) ) { | |
foreach ( $page_template_query->posts as $page ) { | |
echo $page->post_title . '<br />'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment