[wp-hackers] wp_update_post and post_status - possible bug?

Otto otto at ottodestruct.com
Tue Oct 9 17:39:26 UTC 2012


Well, first, you're trying to create a post but not setting
post_date_gmt. Weird things happen when you don't set post_date_gmt.
Here's an easy way to do it:

$post_date_gmt = get_gmt_from_date($post_date);

Secondly, you don't need to decide future or publish for the
post_status. The wp_insert_post code will do that for you. Just set it
to 'publish'. And make sure you have post_date_gmt set correctly.

Might help. Not sure.

-Otto


On Tue, Oct 9, 2012 at 12:19 PM, Ricardo Moraleida <moraleida at gmail.com> wrote:
> Hi there,
>
> i'm in doubt if this is a bug and I should open a trac ticket for it, or it
> is just a case of me doing things the wrong way.
>
> Basically, i'm trying to alter the post_status via wp_update_post() based
> on a datepicker value that the user will choose. Seemed trivial at first,
> but i'm getting sketchy results from it - future-dated posts being
> published and past-dated posts remaining scheduled. Note that applying
> the same values to wp_insert_post() work as expected.
>
> I found this while finishing a project where users would be able to publish
> posts from the front-end. Started telling the story here:
> http://wordpress.stackexchange.com/q/67451/7890
>
> Being stuck in that, i decided to move to a fresh installation with a blank
> theme for testing purposes. The code being tested is this:
> https://gist.github.com/3860049
>
> Test results so far are as follows:
>
> 1) Include post with yesterday's date:
>     $operation = 'include';
>     $post_date = strtotime( "yesterday" );
>
>     Code response (from gist line 52): "publish include"
> *    Result: Post published with the correct date.*
>
> 2) Edit published post and change date from yesterday to today:
>     $operation = 'edit';
>     $post_date = strtotime( "now" );
>
>     Code response: "publish edit"
>     *Result: Post published with today's date*
>
> 3) Edit published post and change date from today to next week
>     $operation = 'edit';
>     $post_date = strtotime( "+1 week" );
>
>     Code response: "future edit"
>     *Result: Post remains published with a date 1 week from today (remains
> visible to users on twenty eleven)*
>
> 4) Include new post scheduled for next week
>     $operation = 'include';
>     $post_date = strtotime( "+1 week" );
>
>     Code response: "future include"
>     *Result: Post is correctly scheduled for a 1 week from today*
>
> 5) Edit back a scheduled post to being published yesterday
>     $operation = 'edit';
>     $post_date = strtotime( "yesterday" );
>
>     Code response: "publish edit"
>     *Result: Post is scheduled with yesterday's date (remains invisible to
> users on twenty eleven)*
>
> This was first noted on 3.4.2 and the later tests were on 3.5-beta1-22133
>
> Any ideas?
>
> Ricardo Moraleida
> _______________________________________________
> 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