On an empty wordpress database, I insert one sample post using the wp_insert_post.

Since it's an empty database, the first post I add ends up with id 1. And I check that in the wp_posts, everything looks right ( well for some reason post_name is blank but I do not want to focus on that now ).

The question is but when I want to update that post ( again using the wp_insert_post), instead of updating the early record, I end up getting post id 2!

If you ask how I update the record with the wp_insert_post, I simply set the ID to 1 when I build my $data array for the wp_insert_post.

The codex say that when you supply the 'ID' array element to the wp_insert_post's $data array, it simply updates that post with that ID.

Well, in my cases, It does not.

I end up getting the post id 2. Post ID 2's author goes as 0 (post id's author was 1 ), and post id 2's post_name is 1-revision ( post id 1s post_name was blank as I said above)

Any idea of why this could be happening?

Or should I simply forget the idea of using wp_insert_post for post updates?

1 Answer 1


You should insert posts with wp_insert_post and update posts with wp_update_post. wp_update_post will add a revision to the database and update the published/draft post data.

  • Thank you. But, I think you meant "wp_insert_post will add a revision..." NOT wp_update_post. Commented Jun 5, 2012 at 4:07
  • No I pull that back. you are right, wp_update_post also does the same thing, it too ads a revision. For a moment, I had thought only wp_insert does that revision thing. But all updates be it thru wp_insert_post or wp_update_post adds the revision post. And there is only one way to get rid of that, which is thru wp-config.php Commented Jun 5, 2012 at 4:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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