您需要利用post_updated
Wordpress的钩子API
// You will need to leverage the <code>save post</code> hook API of Wordpress
add_action( \'post_updated\', \'save_post_callback\', 10, 3 );
//add_action(\'save_post\', \'save_post_callback\');
function save_post_callback($post_ID, $post_after, $post_before){
global $post;
if ($post->post_type != \'page\'){
return;
}
// If you get here then it\'s your post type so do your thing....
// unhook this function so it doesn\'t loop infinitely
remove_action(\'post_updated\', \'save_post_callback\');
$title = $post_after->post_title;
// Check if "NTS00" is already there,
// Deliberately checking if position found is > 0
if( strpos($title, "NTS00") == FALSE ){
// Set the title
$args = array(
\'ID\' => $post_ID,
\'post_title\' => $title.\'_NTS000\'.$post_ID
);
// update the post, which calls save_post again
wp_update_post( $args );
// Bonus!
update_post_meta( $post_ID, \'my_key\', \'NTS000\'.$post_ID );
// re-hook this function
add_action(\'post_updated\', \'save_post_callback\');
}
}
这样,您将确保
NTS00 只追加一次。奖金功能将确保您还为
"custom key" 作为post meta。
我希望我能帮忙。