Setting post_parent during wp_insert_post
-
I’m working on a plugin that creates pages based on searches that are run. I want the new pages to be children of a common results page. For some reason, wp_insert_post is not setting post_parent when pages are created. The relevant parts of the code are as follows:
class wm_mypost {
var $post_title;
var $post_content;
var $post_status;
var $post_author;
var $post_name;
var $post_type;
var $post_parent;
var $comment_status;
var $post_category;
var $tags_input;
}function createPost($searchTerms, $parentID) {
$wm_mypost = new wm_mypost();
$wm_mypost->post_title = $searchTerms;
$wm_mypost->post_content = “[” . $searchTerms . “]”;
$wm_mypost->post_status = ‘publish’;
$wm_mypost->post_author = 1;
$wm_mypost->post_type = ‘page’;
$wm_mypost->comment_status = ‘open’;
$wm_myPost->post_parent = $parentID;
$wm_mypost->tags_input = $searchTerms;$post_ID = wp_insert_post($wm_mypost);
return $postID;
}I’ve verified that $parentID contains the correct value when this function is called, but the new page always ends up with a parentID of 0. What am I missing? Thanks!
- The topic ‘Setting post_parent during wp_insert_post’ is closed to new replies.