wp_insert_post insert a post but return 0

I am trying to insert a page of a theme with after_switch_theme hook .Now when I set the page_template then it insert the post but return 0.

Is there a way to insert a page with specifying a template from the ‘after_switch_theme’ hook?

1 Answer
1

I found the answer. Actually I was passing the template in the wp_insert_post.

When I remove that parameter it returns the post ID. And with that post ID I used

add_post_meta( $page_id, '_wp_page_template', 'tpl-favourites.php' );

to set the template for that page. It is a common technique. I have just dig the code of a standard theme.

Leave a Comment