1

WordPress' command line tool WP-CLI has a post update command for editing individual fields of a specified post.

Two of the standard fields are post_modified and post_modified_gmt, (DATETIME fields in MySQL).

Despite setting them to an earlier date, as below, they are always updated to the current date, e.g.

wp post update 123 --post_modified="2017-12-31 23:55:55"

If I then use wp post get or look at the actual DB, both fields will always show the wrong time, i.e. the time I ran the command rather than the specified time as expected, and in spite of the fact I believe I've entered it in the required format, 0000-00-00 00:00:00.

Adding --debug doesn't give me any useful extra info.

Am I missing something obvious?

William Turrell
  • 3,227
  • 7
  • 39
  • 57

1 Answers1

0

This is not a Bug, rather this is how Wordpress works. It does not allow you to update the post_modified field by the user supplied value. If you are updating a Post, as in your case, Wordpress automatically sets it to the Current Time regardless of what you pass. This is not specific to wp-cli.

Below is the Relevant Code in Core File

3741        if ( $update || '0000-00-00 00:00:00' == $post_date ) {
3742                    $post_modified     = current_time( 'mysql' );
3743                    $post_modified_gmt = current_time( 'mysql', 1 );
3744            } else {
3745                    $post_modified     = $post_date;
3746                    $post_modified_gmt = $post_date_gmt;
3747            }
ascsoftw
  • 3,466
  • 2
  • 15
  • 23