im trying to update a posts date (-1 year), when you hit update. but it causes an infinite loop.
any other ways of doing this?
thanks.
function change_year($post_id, $post){
if ( $post->post_type == 'post' ) {
$format="Y-m-d H:i:s";
$id = $post->ID;
$old_date = $post->post_date;
$old_gmt_date = $post->post_date_gmt;
$new_date = date( $format, strtotime( '-1 year' , strtotime( $old_date ) ) );
$new_date_gmt = date( $format, strtotime( '-1 year' , strtotime( $old_gmt_date ) ) );
$new_values = array (
'ID' => $id,
'post_date' => $new_date,
'post_date_gmt' => $new_date_gmt
);
wp_update_post( $new_values );
}
}
add_filter('save_post', 'change_year',10,2);