Listing pages which uses specific template [duplicate]

You can do this with a WP_Query meta_query. The page template filename is stored in post meta under the key _wp_page_template:

$args = array(
    'post_type' => 'page',
    'posts_per_page' => -1,
    'meta_query' => array(
        array(
            'key' => '_wp_page_template',
            'value' => 'product.php'
        )
    )
);
$the_pages = new WP_Query( $args );

if( $the_pages->have_posts() ){
    while( $the_pages->have_posts() ){
        $the_pages->the_post();
        the_title();
    }
}
wp_reset_postdata();

Leave a Comment