I’ve got the following code in the ‘functions.php’ file of a wordpress theme
$ppost_data = build_post( $pID, $pcontent, $pname, $ptitle, $pstatus, $ptype, $pset_comment_status );
wp_insert_post($ppost_data);
and here’s the ‘build_post()’ function:
function build_post( $pID, $pcontent, $pname, $ptitle, $pstatus, $ptype, $pset_comment_status ) {
return array(
'ID'=>$pID,
'post_content'=>$pcontent,
'post_name'=>$pname,
'post_title'=>$ptitle,
'post_status'=>$pstatus,
'post_type'=>$ptype,
'comment_status'=>$pset_comment_status,
'post_author' => 1
);
The variables are all set, and all of the data is in the $ppost_data
array correctly, but the page isn’t being added. No errors are being thrown. Any ideas?
When inserting a new post, you must omit or leave the
ID
parameter empty, or the post will not be inserted. You can only set theID
if you are updating an existing post with that ID.See
wp_insert_post
in Codex for more information.