UPDATE:
This is now a decade old answer, meant for a very old version of WordPress. I can see the comments informing me that this might not work for newer WP versions, please do refer to the other answers below if mine is not working for your version of WP. For WP 2.*, this will work.
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.
Related Posts:
- Unable to paginate a custom page query
- How to display page content in a page template?
- How to prevent execution of default query, while preserving ability to use WP_Query in template?
- How to stop wordpress to make the default query?
- $wp_query initiation?
- Executing Queries in tag.php
- Does WordPress generate an automatic page for post formats?
- Which custom query am I in and how can I access its properties & methods?
- Single page theme
- Single page theme that uses pages for the content
- Trying to list out child pages with WP_Query
- Order by menu structure
- Targeting specific pages in the loop
- Pass the same object to multiple widgets in a template with one query
- What are the differences between “Latest Posts” and “Static Page”?
- WP_Query not retrieving by random order under parent
- Have functions work outside the loop with 404 override
- Set if condition with wp_nav_menu
- Set order of returned items in the WP_Query() class/function
- Show all post for a given category
- Search pages that are a child of the current page
- How to display summary content from a Page (Not a Post) on another page
- Serve specific “template” page at any URL that ends in its slug
- add_filter(‘query_vars’) not working in custom template
- Display custom tags on pages that have a specific page parent
- Is there a reason why Pages are not publicly_queryable?
- Why post__not_in is ignored?
- Is there a better way to pull in custom content without querying posts?
- Exclude parent with child pages from WP_Query
- WordPress Custom Search Form Displaying Unexpected Results
- Is there a way to make this kind of loop shorter and nicer?
- Create a loop on my pages with new “WP_Query”
- Utilising an existing page while using the “s” query parameter
- All blog data on a page using custom query gives 404 for page 2 and onward
- Get posts in taxonomy randomly
- When listing child pages run out of memory
- WPQuery calling specific posts problem
- How to generate feed for custom template
- WP_Query with multiple orderby NOT working with ASC and DESC, what’s wrong?
- Display specific page (that is child) content on parent page
- Get query results with a page title
- How to get current page nearest parent id?
- How to get main menu only with wp_nav_menu
- How to create single page site in WordPress
- Determine if ID is page or post and query the ID
- How to query for a page, get data, then query for child pages of that page
- Get list of all Grandchild Pages
- Custom query does not find pages
- How to stack name list in non-alphabetical order?
- How to get pages of parent (non-recursive)?
- WP Query and multiple pages
- problem with the loop
- get_children() Archive Template
- In a WP_Query can I force the results’ is_singular() to be set to false?
- How to use custom page for all posts with custom url, call another directory?
- How to display a post(by id) along with css in a page?
- display the children of the post using the current page as the main parent
- ACF: using two loops, the_field returns field content from another loop
- pages shortcode filtering by category
- Is it possible to query a category with specified posts?
- Search Filter With Custom Taxonomy and Custom Fields : How do I handle it via plugin?
- How to create page that lists tags by initial letter?
- Get a page ancestor from a most viewed list
- How can I use a specific wordpress page template if certain words are used in page title [closed]
- Category Archive not working for pages
- History of page, interval of years
- Retrieving category pages from subcategory returns empty sets
- Issue in If else condition [closed]
- Show parent’s child and also child’s, child on a page?
- Passing query variables to a custom page template
- get contents and permalink from a specified page
- Hierarchical List Pages as a table
- Get next post when using pagination with WP_Query?
- Adding css tweak based on page template
- WordPress pagination returns the same posts
- How to write short code with if else to get page_id?
- on attachment.php, how to display previous and next attachment links that follow the same order as a custom WP Query
- How WP determines archive page vs single page?
- How to prevent random 302 canonical-ish redirect on custom template
- Rewrite URL custom search query
- Paginate_Links page 2 doesn’t work
- How to remove “MY WORDPRESS”” Label
- When should you use WP_Query vs query_posts() vs get_posts()?
- When to use WP_query(), query_posts() and pre_get_posts
- WP_Query by just the id?
- Meta_query compare operator explanation
- WP_Query with “post_title LIKE ‘something%'”?
- wp query to get child pages of current page
- How to get an array of post data from wp_query result?
- How to get post id of static front page?
- meta_query with meta values as serialize arrays
- How to only display posts whose meta_value field is not empty?
- Get post ids from WP_Query?
- Pagination when using wp_query?
- Exclude post ID from wp_query
- How to print the excuted sql right after its execution
- How to extend WP_Query to include custom table in query?
- How to store and receive variables in WP sessions?
- Should I use Pre Get Posts or WP_Query
- How can i retrieve default post per page value? from settings->reading. And total number of posts?