Support

Account

Home Forums Front-end Issues Updating post modified date Reply To: Updating post modified date

  • Ok, thanks. I think I was able to get this working. The post_modified date is now updating when we edit on the front end. However, I am also seeing new errors pop up with another plugin, so not sure if I did this right. (It’s possible these errors may not be related.)

    I’m not that familiar with the wpdb class so let me know if anything looks incorrect.

    Here is my code:

    function my_acf_save_post( $post_id ) {
    
      // bail out early if we don't need to update the date
      if( is_admin() || $post_id == 'new' ) {
    
         return;
    
       }
    
       global $wpdb;
    
       $datetime = date("Y-m-d H:i:s");
    
       $query = "UPDATE $wpdb->posts
    	     SET
                  post_modified = '$datetime'
                 WHERE
                  ID = '$post_id'";
    
        $wpdb->query( $query );
    
    }
    
    // run after ACF saves the $_POST['acf'] data
    add_action('acf/save_post', 'my_acf_save_post', 20);
    

    Thanks!