Categories
WordPress

Identifying Custom Templates in WordPress

Sometimes, particularly when you’ve taken over the development of an existing WordPress-based website, its handy to be able to tell which of the custom templates in the theme folder are actively in use and by which pages. The following SQL query gives you that information.

SELECT p.ID, p.post_title AS Page, p.post_status AS Status, m.meta_value AS Template
FROM wp_posts p
LEFT JOIN wp_postmeta m ON p.ID = m.post_id
WHERE m.meta_key = '_wp_page_template'
ORDER BY p.post_title