Read our latest blog posts, learn something new, find answers, and stay up to date.

Query All Custom Page Templates in WordPress

Make your WordPress quality assurance easier by using this custom query to easily find all custom pages templates and the pages that use them.

Here is a query you can use/run to find an example of any custom page template created and used on your WordPress site:

The Custom Page Templates Query

SELECT posts.ID, meta.meta_value
FROM wp_posts AS posts
LEFT JOIN wp_postmeta AS meta ON posts.ID = meta.post_ID
AND meta.meta_key = '_wp_page_template'
WHERE posts.post_status = 'publish'
AND meta.meta_value IS NOT NULL
GROUP BY meta.meta_value

The Custom Page Templates Results

That query will then return results that show the post ID as well as the page template file name so you can then easily see all your custom page templates in place. (See image below as an example)

Using the Results for Quality Assurance

In order to then actually see the pages that use the custom page templates, you would use the following URL format:{ID}

Real world example using this web site as well as the post ID of 123:

To do your final QA – you would just substitute the post ID with each found in the query results. You can then be sure you have tested a sample of each custom page template.