WordPress query pages with certain template

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

Related posts

Leave a Reply

1 comment

  1. 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)
    ?>