Problem with wp_update_post

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 );
            }   
}

1 Answer
1

The first argument of array_merge is the array of old values pulled from the original post, not your new values, so I’d guess you’re passing an invalid post ID. In your array of new values, I think you want to set post ID to $page_check_404->ID, not $ss_404_post_id.

Leave a Comment