当你点击更新时,我正在尝试更新帖子日期(-1年)。但它会导致无限循环。
还有其他方法吗?
谢谢
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);