--- C:\Users\User\Documents\www\wp\wp-includes\post-orig.php
+++ C:\Users\User\Documents\www\wp\wp-includes\post.php
@@ -3650,6 +3650,30 @@
 }
 
 /**
+ * Gets a unique post slug using a supplied SQL query for getting the latest appropriate slug.
+ *
+ * @global wpdb	 $wpdb 			WordPress database abstraction object.
+ * 
+ * @param string $slug			The desired slug (post_name).
+ * @param string $last_slug_sql	An SQL query returning the latest appropriate slug.
+ * @param array	 $prep_args		Parameters for the SQL query for using in $wpdb->prepare() call.
+ */
+function _get_unique_post_slug( $slug, $last_slug_sql, $prep_args ) {
+	global $wpdb;
+	
+	$suffix = 2;
+	$last_slug_prep = $wpdb->prepare($last_slug_sql, $prep_args);
+	
+	$last_slug = $wpdb->get_var($last_slug_prep);
+	$last_suffix = substr($last_slug, strlen($slug) + 1);	
+			
+	if ($last_suffix)
+		$suffix = $last_suffix + 1;
+			
+	$slug = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-{$suffix}";
+	return $slug;
+}
+/**
  * Computes a unique slug for the post, when given the desired slug and some post details.
  *
  * @since 2.8.0
@@ -3690,25 +3714,19 @@
 		 * @param string $slug     The post slug.
 		 */
 		if ( $post_name_check || in_array( $slug, $feeds ) || 'embed' === $slug || apply_filters( 'wp_unique_post_slug_is_bad_attachment_slug', false, $slug ) ) {
-			$suffix = 2;
-			do {
-				$alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
-				$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_ID ) );
-				$suffix++;
-			} while ( $post_name_check );
-			$slug = $alt_post_name;
+			$last_slug_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name LIKE %s ORDER BY id DESC LIMIT 1";
+			$slug = _get_unique_post_slug($slug, $last_slug_sql, array($wpdb->esc_like($slug) . '%'));
 		}
 	} elseif ( is_post_type_hierarchical( $post_type ) ) {
 		if ( 'nav_menu_item' == $post_type )
 			return $slug;
-
 		/*
 		 * Page slugs must be unique within their own trees. Pages are in a separate
 		 * namespace than posts so page slugs are allowed to overlap post slugs.
 		 */
 		$check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( %s, 'attachment' ) AND ID != %d AND post_parent = %d LIMIT 1";
 		$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_type, $post_ID, $post_parent ) );
-
+		
 		/**
 		 * Filters whether the post slug would make a bad hierarchical post slug.
 		 *
@@ -3720,13 +3738,8 @@
 		 * @param int    $post_parent Post parent ID.
 		 */
 		if ( $post_name_check || in_array( $slug, $feeds ) || 'embed' === $slug || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug )  || apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent ) ) {
-			$suffix = 2;
-			do {
-				$alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
-				$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_ID, $post_parent ) );
-				$suffix++;
-			} while ( $post_name_check );
-			$slug = $alt_post_name;
+			$last_slug_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name LIKE %s AND post_type IN ( %s, 'attachment' ) AND post_parent = %d ORDER BY id DESC LIMIT 1";
+			$slug = _get_unique_post_slug($slug, $last_slug_sql, array($wpdb->esc_like($slug) . '%', $post_type, $post_parent));
 		}
 	} else {
 		// Post slugs must be unique across all posts.
@@ -3765,13 +3778,8 @@
 		 * @param string $post_type Post type.
 		 */
 		if ( $post_name_check || in_array( $slug, $feeds ) || 'embed' === $slug || $conflicts_with_date_archive || apply_filters( 'wp_unique_post_slug_is_bad_flat_slug', false, $slug, $post_type ) ) {
-			$suffix = 2;
-			do {
-				$alt_post_name = _truncate_post_slug( $slug, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
-				$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $alt_post_name, $post_type, $post_ID ) );
-				$suffix++;
-			} while ( $post_name_check );
-			$slug = $alt_post_name;
+			$last_slug_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name LIKE %s AND post_type = %s ORDER BY id DESC LIMIT 1";
+			$slug = _get_unique_post_slug($slug, $last_slug_sql, array($wpdb->esc_like($slug) . '%', $post_type));
 		}
 	}
 
