Skip to content

Instantly share code, notes, and snippets.

@efuller
Created January 27, 2017 20:00
Show Gist options
  • Save efuller/19805567d07f1704c88d93017310588e to your computer and use it in GitHub Desktop.
Save efuller/19805567d07f1704c88d93017310588e to your computer and use it in GitHub Desktop.
List WordPress pages using a template.
<?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