I recently added a function to reset the publish date when a user updates a page. The code is as follows, thanks to @s_ha_dum for it because it works great except for one annoying instance.

function reset_post_date_wpse_121565($data,$postarr) {
// var_dump($data,$postarr); die; // debug
$data['post_date'] = $data['post_modified'];
$data['post_date_gmt'] = $data['post_modified_gmt'];
return $data;}


I noticed it works as intended for posts and pages but I have a custom taxonomy where, when I update one item, in this case 'property' it updates the publish date for all of that same taxonomy. Any idea how to avoid this from happening?


  • Do you save taxonomy or custom post type? Aug 24, 2017 at 11:53

1 Answer 1


You could also hook into the save_{$post_type} action, which fires only when a certain post type is updated. This hook passes to post's ID to the callback function:

add_action( 'save_post', 'my_callback_function' );
function my_callback_function( $post_id ){

    if ( ! wp_is_post_revision( $post_id ) ){

        // Unhook this function so it doesn't loop infinitely
        remove_action('save_post', 'my_callback_function');

        // Update post's data
          $post = array(
              'ID'              => $post_id,
              'post_date'       => current_time( 'mysql' ),
              'post_date_gmt'   => current_time( 'mysql', 1 ),

        // Update the post, which calls save_post again
        wp_update_post( $post );

        // Re-hook this function
        add_action('save_post', 'my_callback_function');

  • Thanks for the timely response! Unfortunately it is still updating the publishing date for all 'properties'
    – Patrik
    Aug 24, 2017 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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