[wp-trac] [WordPress Trac] #31331: $post->post_date displays current time if status is pending or draft

WordPress Trac noreply at wordpress.org
Sat Feb 14 17:11:47 UTC 2015

#31331: $post->post_date displays current time if status is pending or draft
 Reporter:  danbrellis         |      Owner:
     Type:  defect (bug)       |     Status:  new
 Priority:  normal             |  Milestone:  Awaiting Review
Component:  Posts, Post Types  |    Version:  4.1
 Severity:  normal             |   Keywords:
  Focuses:                     |
 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

 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.

Ticket URL: <https://core.trac.wordpress.org/ticket/31331>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list