wordpress change last modified date of the post to post date (scheduled post)

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.

Read More

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?

Related posts

Leave a Reply

2 comments

  1. 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);
    
  2. 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