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.


1 Answer 1


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.

  • Excellent approach, works perfectly. Thanks a lot!
    – Marcos
    Jan 21, 2012 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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