Is there a way to query Wordpress pages that have certain template? Here's what I got, but doesn't show anything:
<?php $my_query = new WP_Query(array( 'meta_key' => '_wp_page_template', 'meta_value' => 'template-city.php' )); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li>
<?php the_title(); ?>
</li>
<?php endwhile; ?>
Of course, there is page template file named template-city.php
if post_type
is left out WP will look for post, and you are looking for pages.
<?php
$args = array(
'post_type' => 'page',//it is a Page right?
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => '_wp_page_template',
'value' => 'template-city.php', // template name as stored in the dB
)
)
);
$my_query = new WP_Query($args)
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With