Make WordPress Core

#51427 closed defect (bug) (duplicate)

wp_publish_post function does not check for unique postname in database

Reported by: mihirgosai Owned by:
Milestone: Priority: normal
Severity: major Version: 5.5.1
Component: Posts, Post Types Keywords:
Focuses: administration Cc:

Description (last modified by SergeyBiryukov)

If we use wp_publish_post function to change status of post, it does not check for unique postname (slug) from database. It can end up having two or more posts with same postname (slug).

Solution is to use code as below in wp-includes/post.php:
(function name: wp_publish_post)

$post->post_name = wp_unique_post_slug($post->post_name, $post->ID, 'publish', $post->post_type, $post->post_parent);

$wpdb->update( $wpdb->posts, array( 'post_status' => 'publish', 'post_name' => $post->post_name), array( 'ID' => $post->ID ) );

Change History (1)

#1 @SergeyBiryukov
15 months ago

  • Description modified (diff)
  • Keywords dev-feedback removed
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Hi there, welcome to WordPress Trac!

Thanks for the report, we're already tracking this issue in #50447.

Note: See TracTickets for help on using tickets.