WordPress Template_page meta key and update_post_meta

This post will be a fairly simple and straight forward one. It has been a long time since i wrote anything on Hungred Dot Com. I really like to write more regarding my experiences during each of my project and some useful designing list that i would like to keep but i just can't seems to get the time. Nonetheless, i would still write such article that i couldn't find on Google to share with people who needs it.

Template_page Meta Key

Since 9 of January 2009, WordPress has removed template_page key from wp_insert_post from the table wp_post to wp_meta_post. Therefore, some of you who are looking for this particular key to insert customize template will find difficulty as there are no documentation of any kind that allows you to work this out peacefully. The changes will require user to use update_post_meta in order to interact with wp_meta_post table. Hence, our main concern here is the exact key used to update any particular post/page template using the method update_post_meta. I dig around and found out that WordPress no longer uses Template_page as the key but uses _wp_page_template as the key for our meta post table. Hence, you will write something like this in order to update a particular post/page template.

update_post_meta($id, "_wp_page_template", "new_template.php");

The third parameter will require you to place in the exact file name plus extension. Without extension but pure name won't work. Once this sentence is being executed, your post which has the id in the variable $id will have new_template.php as its own template! Enjoy!