Programmatically change post templates?

I take it that you mean saving the pages with a new post-template to the DB? see if there’s anything in the post object that refers to the page-template, if so craft a query that updates that.

Update:

Taken from the wp_insert_post documentation

NOTE: The page_template key was removed from the $post table and is
now located in the wp_postmeta table. To set the page template of a
page, use update_post_meta instead with a meta key of
_wp_page_template.

So you can fetch the page template using get_post_meta, and update it with update_post_meta (Or set it with add_post_meta)

Leave a Comment