From 0983dd3c0000330c4eedae6ca99ef1d39d311cfa Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Tue, 21 Aug 2007 00:11:46 +0000 Subject: [PATCH] Really make slugs unique during upgrade. fixes #4776 git-svn-id: https://develop.svn.wordpress.org/trunk@5908 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/includes/upgrade.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/wp-admin/includes/upgrade.php b/wp-admin/includes/upgrade.php index 097fc5f318..5f9ae2ed24 100644 --- a/wp-admin/includes/upgrade.php +++ b/wp-admin/includes/upgrade.php @@ -538,11 +538,17 @@ function upgrade_230() { // Associate terms with the same slug in a term group and make slugs unique. if ( $exists = $wpdb->get_results("SELECT term_id, term_group FROM $wpdb->terms WHERE slug = '$slug'") ) { - $num = count($exists); - $num++; - $slug = $slug . "-$num"; $term_group = $exists[0]->term_group; $id = $exists[0]->term_id; + $num = 2; + do { + $alt_slug = $slug . "-$num"; + $num++; + $slug_check = $wpdb->get_var("SELECT slug FROM $wpdb->terms WHERE slug = '$alt_slug'"); + } while ( $slug_check ); + + $slug = $alt_slug; + if ( empty( $term_group ) ) { $term_group = $wpdb->get_var("SELECT MAX(term_group) FROM $wpdb->terms GROUP BY term_group") + 1; $wpdb->query("UPDATE $wpdb->terms SET term_group = '$term_group' WHERE term_id = '$id'");