3

I've had a read of the existing posts on here and still can't see why my instance is doing this, but I'm using wp_insert_post to add a post with some data it's given, and it's inserting the post just fine but the function is returning 0 in place of the post ID - does it have to be triggered to use this?

    $ember_prepare_post = array(
    'post_author' => $ember_current_user_id,
    'post_category' => $ember_post_category,
    'post_content' => $ember_post_content,
    'post_title' => $ember_post_title,
    'post_status' => 'publish',
    'post_excerpt' => $ember_post_excerpt,
    'tags_input' => $ember_post_tags
    );

// now we've prepared an array with the data, we're going to save it into the WP database and obtain the resulting post ID.

$ember_newpost_id = wp_insert_post($ember_prepare_post, true);

I'm not seeing any errors, and have had a read of the wp_insert_post function itself and cannot see why it wouldn't work. The ID's of the posts it creates definitely aren't zero, either.

Thanks!

  • 1
    Are you passing this "$ember_post_category" as an array? It should be. – Banago Jul 29 '11 at 7:19
  • I'm having a similar problem - wish this weren't closed back in the day. Ours is giving errors (a warning, technically) when we try to create a new post in the admin interface. The warning can be traced back to this issue - I'm thinking it's a problem in our database somewhere... The warning message is: Warning: Creating default object from empty value in /home/xxx/public_html/wp-admin/includes/post.php on line 475 – rinogo Dec 3 '14 at 19:44
  • FYI, the solution to our particular problem was: eddiemoya.com/plugins/incorrect-datetime-bug-fix-wordpress – rinogo Dec 3 '14 at 20:03

Browse other questions tagged or ask your own question.