1

I have an idea to change the value of post_modified, so the value will have the same value with the post_date.

But Wordpress has a revision system, so I want to change the post_modified on the revision to have a same value with post_date.

Here is my query to change it:

$query = "UPDATE $wpdb->posts 
          SET 
              post_modified = '$recent->post_date',
              post_modified_gmt = '$recent->post_date_gmt'
          WHERE 
              ID = '$update->ID'";

$wpdb->query($query);


$recent->post_date is the post_date (scheduled time / time where our post will appear in the website)

$recent->post_date_gmt is post_date_gmt

$update->ID is the revision ID in posts table.

But when I run the query, it doesn't change the value and stops my plugin.

Is there something I missed? Or is it that Wordpress itself doesn't allow us to change the post_modified?

Krease
  • 15,805
  • 8
  • 54
  • 86
Andi R
  • 112
  • 2
  • 13

2 Answers2

2

You can use the normal wp_update_post function

    $args = new stdClass;
    $args->ID = $yourPostIdVal;
    $args->post_modified = $yourDateString;
    $args->post_modified_gmt = $yourGmDateString;
    wp_update_post($args);
JRalph
  • 21
  • 2
0

I have faced same like this problem when I tried to update post_date.Finally I used "`" mark to wrap column names.Do that exactly as follows.

$postID = $update->ID;
$datetime = date("Y-m-d H:i:s");   



$wpdb->query( "UPDATE `$wpdb->posts` SET 
                                    `post_date` = '".$datetime."'
                                    WHERE `ID` = '".$postID."'" );

Remember, $datetime is a valid date, like 2015-01-04 or 2015-01-04 23:59:59

Hope this would be help. Thanks

Sumith Harshan
  • 6,325
  • 2
  • 36
  • 35