From 1a2ed535e9dea7efd8028fe8ea7b6a570677a727 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Wed, 7 Dec 2005 19:02:05 +0000 Subject: [PATCH] Make page slugs unique. Props skeltoac. fixes #2034 git-svn-id: https://develop.svn.wordpress.org/trunk@3277 602fd350-edb4-49c9-b593-d223f7449a82 --- 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 15416f321e..557945f8d0 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;