[wp-trac] [WordPress Trac] #36595: can't set post_modified in wp_insert_post, becomes post_date

WordPress Trac noreply at wordpress.org
Tue Apr 19 16:52:39 UTC 2016


#36595: can't set post_modified in wp_insert_post, becomes post_date
-------------------------------+------------------------------
 Reporter:  gijsgg             |       Owner:
     Type:  defect (bug)       |      Status:  new
 Priority:  normal             |   Milestone:  Awaiting Review
Component:  Posts, Post Types  |     Version:  4.5
 Severity:  normal             |  Resolution:
 Keywords:                     |     Focuses:
-------------------------------+------------------------------

Comment (by Latz):

 Let's take a look at the code ( wp-includes/post.php,  line 3192)

 {{{
 function wp_insert_post() {

 [...]

 if ( $update || '0000-00-00 00:00:00' == $post_date ) {
                 $post_modified     = current_time( 'mysql' );
                 $post_modified_gmt = current_time( 'mysql', 1 );
         } else {
                 $post_modified     = $post_date;
                 $post_modified_gmt = $post_date_gmt;
         }
 }}}

 Well it seems, that the `$post_modified_date` defined in the parameter
 array isn't used at all. The logic looks like this:

 If the post is going to be updated (`$update == true`) or the `$post_date`
 isn't set (0000-00-00 00:00:00, evaluated some lines above) the current
 time is used; otherwise the `$post_modified_date` is set to the current
 time.

 According to the phpdoc this isn't the desired behaviour but the one you
 expected:
 {{{
  *     @type string $post_modified         The date when the post was last
 modified. Default is
  *                                         the current time.
  *     @type string $post_modified_gmt     The date when the post was last
 modified in the GMT
  *                                         timezone. Default is the
 current time.
 }}}

 I'm going to work on a patch if there aren't any other opinions...

--
Ticket URL: <https://core.trac.wordpress.org/ticket/36595#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list