最后,我自己找到了答案。
//add our action
add_action( \'save_post\', \'my_save_post\', 11, 2 );
function my_save_post($post_id, $post){
//if it is just a revision don\'t worry about it
if (wp_is_post_revision($post_id))
return false;
//if the post is an auto-draft we don\'t want to do anything either
if($post->post_status != \'auto-draft\' ){
// unhook this function so it doesn\'t loop infinitely
remove_action(\'save_post\', \'my_save_post\' );
//this is where it happens -- update the post and change the post_name/slug to the post_title
wp_update_post(array(\'ID\' => $post_id, \'post_name\' => str_replace(\' \', \'-\', $_POST[\'post_title\'])));
//re-hook this function
add_action(\'save_post\', \'my_save_post\' );
}
}