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

Ricardo Moraleida moraleida at gmail.com
Tue Oct 9 17:19:46 UTC 2012


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


More information about the wp-hackers mailing list