Trouble with page_template key for wp_insert_post
-
Using wp_insert_post (https://codex.www.ads-software.com/Function_Reference/wp_insert_post) I can set a value for the page_template key:
‘page_template => [ <template file> ] //Sets the template for the page.However, I’ve not been able to do this successfully.
I want to use a custom theme page (page-proposal.php) in the theme directory properly named as “Page Proposal”. My custom form uses wp_insert_post as follows (in part):
$prop_page = array();
…
$prop_page[‘page_template’] = ‘page-proposal.php’;
…
wp_insert_post($prop_page);Though everything else in the array goes through fine, the new page’s template ends up as “default”. I checked the db and found the entries in the wp_postmeta table ending up as
_wp_page_template default
When I change the template through the GUI everything’s OK, and the db updates properly. This makes me think that my wp_insert_post() isn’t sending the page_template value to the right place.
Ideas?
- The topic ‘Trouble with page_template key for wp_insert_post’ is closed to new replies.