WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to retrieve pages with determinate template assigned. Function get_pages() hasn´t any parameter to select by template. For exmaple if I created three pages: Home, Page 1 and Portfolio. After I asigned default template to Home and Page but asigned "portfolio template" to Portfolio Page. How can I get only the pages that are using "portfolio template" for example?

If you know a function to push my in right direction, please advise me.


share|improve this question
up vote 0 down vote accepted

Without knowing exactly what you're trying to acheive, it's difficult to know if using page templates for this is the best solution, or if you should consider using a Custom Post Type for portfolio items, and then a custom archive page to display them. Anyway, I digress...

The template a page is set to use, is defined in the post meta using the key _wp_page_template. If you use the query_posts method instead of get_pages you can also use the meta values as part of the query.

In my example, the filename of the Portfolio page template is page-portfolio.php. You'll need to change the query below to match yours.

    'post_type' =>'page',
    'meta_key'  =>'_wp_page_template',

If you use this query in your template file, you can then use the normal WordPress loop to iterate over the results. You can also add all the other possible parameters to the query to refine it further if you wish.

share|improve this answer
Excellent approach, works perfectly. Thanks a lot! – Marcos Jan 21 '12 at 12:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.