From c8b54e3bbae72422d05462aff934c428ef2d4b80 Mon Sep 17 00:00:00 2001 From: ryan Date: Wed, 7 Dec 2005 19:02:05 +0000 Subject: [PATCH] Make page slugs unique. Props skeltoac. fixes #2034 git-svn-id: http://svn.automattic.com/wordpress/trunk@3277 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions-post.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/wp-includes/functions-post.php b/wp-includes/functions-post.php index 15416f321..557945f8d 100644 --- a/wp-includes/functions-post.php +++ b/wp-includes/functions-post.php @@ -98,13 +98,18 @@ function wp_insert_post($postarr = array()) { if ( !isset($post_password) ) $post_password = ''; - if ('publish' == $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"); + if ( ('publish' == $post_status) || ('static' == $post_status) ) { + $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) { $suffix = 2; while ($post_name_check) { $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++; } $post_name = $alt_post_name;