Make WordPress Core

Opened 6 years ago

Closed 6 years ago

#51427 closed defect (bug) (duplicate)

wp_publish_post function does not check for unique postname in database

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

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
6 years ago

  • Description modified (diff)
  • Keywords dev-feedback removed
  • Milestone Awaiting Review
  • Resolutionduplicate
  • Status newclosed

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.