0

On my site, I display each post's Last Updated date instead of its Published date in order to let visitors know how recent the post is.

I'm currently developing a new theme, and some of the features I'm building will require me to make edits to almost every post's featured image and custom fields.

I'd like to prevent the Last Updated date from being changed when I do these updates, as I'm not really updating the content.

Any way to do this? My current idea is to simply change the names of the post_modified and post_modified_gmt while I do the update - will this break anything, since WordPress will be trying to update columns that technically don't exist?

0

Add the following to functions.php when you are meddling and remove it after, or comment it out:

function no_mod_wpse_136092($data,$postarr){
  if (empty($postarr['ID'])) return $data;
  $old = get_post($postarr['ID']);
  if (!empty($old)) {
    $data['post_modified'] = $old->post_modified;
    $data['post_modified_gmt'] = $old->post_modified_gmt;
  }
  return $data;
}
add_action('wp_insert_post_data','no_mod_wpse_136092',10,2);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.