2

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

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.

  • That's exactly what was wrong, thank you! Just a quick follow up, why is it that $page_check_404->ID works but not $ss_404_post_id? Doesn't $ss_404_post_id = wp_insert_post( $ss_404_page ); store the post ID in $ss_404_post_id on post creation? – Jeremiah Prummer Jan 20 '13 at 16:15
  • if the page already exists then $ss_404_post_id won't be set, you're only setting it in the if(!isset($page_check_404->ID)) check. – Milo Jan 20 '13 at 16:33
  • Okay, well thanks for your help. I really appreciate it! – Jeremiah Prummer Jan 20 '13 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.