Wordpress - Page template query with WP_Query

Try this... Assuming the template name is 'my_template.php',

$query = new WP_Query(
    array(
        'post_type' => 'page',
        'meta_key' => '_wp_page_template',
        'meta_value' => 'my_template.php'
    )
);
//Down goes the loop...

You can also use get_posts, or modify query posts to get the job done. Both these functions use the same parameters as WP_Query.


Incorrect: as of wordpress 3 you need something akin to:

$args = array(
    'post_type'  => 'page', 
    'meta_query' => array( 
        array(
            'key'   => '_wp_page_template', 
            'value' => 'my_template.php'
        )
    )
);