Make page slugs unique. Props skeltoac. fixes #2034

git-svn-id: http://svn.automattic.com/wordpress/trunk@3277 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2005-12-07 19:02:05 +00:00
parent 1547da4733
commit c8b54e3bba
1 changed files with 8 additions and 3 deletions

View File

@ -98,13 +98,18 @@ function wp_insert_post($postarr = array()) {
if ( !isset($post_password) ) if ( !isset($post_password) )
$post_password = ''; $post_password = '';
if ('publish' == $post_status) { if ( ('publish' == $post_status) || ('static' == $post_status) ) {
$post_name_check = $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$post_name' AND post_status = 'publish' AND ID != '$post_ID' LIMIT 1"); $post_name_check = ('publish' == $post_status)
? $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$post_name' AND post_status = 'publish' AND ID != '$post_ID' LIMIT 1")
: $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$post_name' AND post_status = 'static' AND ID != '$post_ID' AND post_parent = '$post_parent' LIMIT 1");
if ($post_name_check) { if ($post_name_check) {
$suffix = 2; $suffix = 2;
while ($post_name_check) { while ($post_name_check) {
$alt_post_name = $post_name . "-$suffix"; $alt_post_name = $post_name . "-$suffix";
$post_name_check = $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$alt_post_name' AND post_status = 'publish' AND ID != '$post_ID' LIMIT 1"); $post_name_check = ('publish' == $post_status)
? $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$alt_post_name' AND post_status = 'publish' AND ID != '$post_ID' LIMIT 1")
: $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$alt_post_name' AND post_status = 'static' AND ID != '$post_ID' AND post_parent = '$post_parent' LIMIT 1");
$suffix++; $suffix++;
} }
$post_name = $alt_post_name; $post_name = $alt_post_name;