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 2


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:

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;

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.