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

Ricardo Moraleida moraleida at gmail.com
Tue Oct 9 18:20:52 UTC 2012


Another bit of info.

When a test gives me a published post with a future date, if I just click
on Quick Edit and Update, it then becomes correctly scheduled.

Ricardo Moraleida



2012/10/9 Ricardo Moraleida <moraleida at gmail.com>

> Hi, Otto,
>
> thanks for the reply, i was trying to use the less info I could to pass
> into the insert/update functions, but I didn't know abou the caveats of
> post_date_gmt.
>
> just ran the tests again using:
>
> $newpostdata['post_status'] = 'publish';
> $newpostdata['post_date'] = date( 'Y-m-d H:i:s', $post_date );
> $newpostdata['post_date_gmt'] = get_gmt_from_date($post_date);
>
> Test results changed a bit, but they're still sketchy:
>
> Test #3 still rendered a published (visible) post with next week's date
> (should be scheduled)
> Test #4 now rendered a published (visible) post with next week's
> date (should be scheduled - was ok before)
> Test #5 now rendered a published post with yesterdays date (correct)
>
> Because of Test #4 i ran the tests again, specifying 'future' when needed
> and got the exact same results. Then I took out post_date_gmt and ranTest
> #4 again, this time rendering the correct results.
>
> And I remain puzzled.
>
> Ricardo Moraleida
>
>
>
>
> 2012/10/9 Otto <otto at ottodestruct.com>
>
>> 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
>> _______________________________________________
>> 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