实际上,如果查看核心函数wp\\u insert\\u post(post.php),您将看到它执行以下操作:
$data[\'post_name\'] = wp_unique_post_slug( sanitize_title( $data[\'post_title\'], $post_ID ), $post_ID, $data[\'post_status\'], $post_type, $post_parent );
$wpdb->update( $wpdb->posts, array( \'post_name\' => $data[\'post_name\'] ), $where );
需要注意的关键是,使用wp\\u unique\\u post\\u slug和sanitize\\u标题:
wp_unique_post_slug( sanitize_title(