Where is the custom template file that has been selected through the wordpress edit screen (for a post or page) stored in the wordpress database?
2 Answers
It's in the post meta table (usually wp_postmeta
), with the page id in post_id, meta_key with _wp_page_template
and meta_value with the template file name.
Example select query:
SELECT *
FROM wp_postmeta
WHERE meta_key = '_wp_page_template'
# AND post_id = 50
Example update query:
UPDATE wp_postmeta
SET meta_value = 'templates/template-example.php'
WHERE meta_key = '_wp_page_template'
AND post_id = 50;