[wp-hackers] weird behavior usig wp_insert_post

William P. Davis will.davis at gmail.com
Tue Jun 5 02:12:53 UTC 2012


Haluk,
This is expected behavior - these are post revisions.  Post ID 1 remains the primary post and Post ID 2 is the earlier version. Post ID 2 has a different post type and post status than general posts. You can disable revisions by adding define ('WP_POST_REVISIONS', 0); to wp-config
Sent from my BlackBerry

-----Original Message-----
From: Haluk Karamete <halukkaramete at gmail.com>
Sender: wp-hackers-bounces at lists.automattic.com
Date: Mon, 4 Jun 2012 19:06:51 
To: <wp-hackers at lists.automattic.com>
Reply-To: wp-hackers at lists.automattic.com
Subject: [wp-hackers] weird behavior usig wp_insert_post

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?
_______________________________________________
wp-hackers mailing list
wp-hackers at lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers


More information about the wp-hackers mailing list