[wp-hackers] weird behavior usig wp_insert_post

Haluk Karamete halukkaramete at gmail.com
Tue Jun 5 02:06:51 UTC 2012

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

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

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?

More information about the wp-hackers mailing list