WordPress.org

Make WordPress Core

Ticket #12634: 12634.diff

File 12634.diff, 955 bytes (added by solarissmoke, 3 years ago)

Check for attachments sharing the same parent as the current page when finding a unique slug

  • wp-includes/post.php

     
    27872787                } 
    27882788        } elseif ( in_array( $post_type, $hierarchical_post_types ) ) { 
    27892789                // Page slugs must be unique within their own trees. Pages are in a separate 
    2790                 // namespace than posts so page slugs are allowed to overlap post slugs. 
     2790                // namespace than posts so page slugs are allowed to overlap post slugs. But they must not 
     2791                // overlap slugs of attachments sharing the same parent. 
     2792                $hierarchical_post_types['attachment'] = 'attachment'; 
     2793                 
    27912794                $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( '" . implode( "', '", esc_sql( $hierarchical_post_types ) ) . "' ) AND ID != %d AND post_parent = %d LIMIT 1"; 
    27922795                $post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_ID, $post_parent ) ); 
    27932796