I’m trying to write a plugin that creates a page if a box is checked (value 1) and if the post id doesn’t already exist. If the post id does already exist, then I want to update the post with whatever changes have been made. I have the creating post (as page) part working just fine. However, when I try to do run the wp_update_post I get this error:
array_merge() [function.array-merge]: Argument #1 is not an array in /home/wpovernight/wpovernight.com/wp-includes/post.php on line 2996
Since the error is concerning post.php, I’m guessing this issue is with array on wp_update_post, but I’m not sure what I’m doing wrong. It all looks fine to me. Here’s my code:
//Check if page exists
$page_check_404 = get_page_by_title($page_title_404);
// Checks if box is checked
if ($activate_404_page == 1) {
$ss_404_page = array(
'post_title' => $page_title_404,
'post_content' => $ss_404_page_content,
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'page'
);
// If page doesn't exist, create it
if(!isset($page_check_404->ID)){
$ss_404_post_id = wp_insert_post( $ss_404_page );
}
//if page does exist, edit it
if(isset($page_check_404->ID)){
$ss_404_page_update = array(
'post_title' => $page_title_404,
'ID' => $ss_404_post_id,
'post_content' => $ss_404_page_content,
'post_status' => 'publish',
'post_author' => 1,
'post_type' => 'page'
);
wp_update_post( $ss_404_page_update );
}
}