From 395831fc10c39eb74937c4fb2eb896c89743ee24 Mon Sep 17 00:00:00 2001
From: hughie molloy <hughie.molloy@kaldorgroup.com>
Date: Mon, 22 Jun 2020 17:49:45 +0100
Subject: [PATCH] Fixing an error with non unique post names when transitioning
 a post to publish in wp_publish_post

---
 wp-includes/post.php | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/wp-includes/post.php b/wp-includes/post.php
index c123ff47ac..e4ff64feed 100644
--- a/wp-includes/post.php
+++ b/wp-includes/post.php
@@ -4318,6 +4318,8 @@ function wp_update_post( $postarr = array(), $wp_error = false ) {
 /**
  * Publish a post by transitioning the post status.
  *
+ * Makes sure the new permalink is unique.
+ *
  * @since 2.1.0
  *
  * @global wpdb $wpdb WordPress database abstraction object.
@@ -4336,7 +4338,9 @@ function wp_publish_post( $post ) {
 		return;
 	}
 
-	$wpdb->update( $wpdb->posts, array( 'post_status' => 'publish' ), array( 'ID' => $post->ID ) );
+    $post_name = wp_unique_post_slug( $post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent );
+
+    $wpdb->update( $wpdb->posts, array( 'post_status' => 'publish', 'post_name' => $post_name ), array( 'ID' => $post->ID ) );
 
 	clean_post_cache( $post->ID );
 
-- 
2.20.1

