Make WordPress Core

Opened 9 years ago

Last modified 5 years ago

#31331 new defect (bug)

$post->post_date displays current time if status is pending or draft

Reported by: danbrellis's profile danbrellis Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.1
Component: Posts, Post Types Keywords:
Focuses: Cc:


Create a new post and save as a draft or save as 'pending'. On single.php enter these lines of code:

global $post;
var_dump(date("Y-m-d H:i:s")); //current time

If you wait about 5 minutes to refresh the front-end page after saving the post as draft/pending, you'll notice that the current time and the $post->post_date are the same (accounting for timezone differences). Further more, if you refresh the page after another 5 minutes, the $post->post_date will change. However, the $post->post_date and $post->post_modified are different. When comparing to the database values, the $post->post_modified matches its database value, but $post->post_date will continue to match the current time and not what is in the database for post_date.

It seems to me that the post object should reflect what is in the database regardless of the post_status. If a post is draft/pending, it is inconsistent to use post_date to note when the post was originally created.

I can see the code that is responsible for this is on wp-includes/query.php on line 3527-3528:

if ( 'future' != $status )
$this->posts[0]->post_date = current_time('mysql');

I apologize if I'm thinking about this wrongly.

Change History (1)

#1 @tyxla
9 years ago

This behavior was introduced in #2164 - changeset [3458].

Last edited 9 years ago by tyxla (previous) (diff)
Note: See TracTickets for help on using tickets.