您还可以连接到save_{$post_type}
操作,仅在更新某个帖子类型时激发。此挂钩将post的ID传递给回调函数:
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\');
}
}