WordPress.org

Make WordPress Core

Ticket #6437: 9437.2.diff

File 9437.2.diff, 1.6 KB (added by Denis-de-Bernardy, 9 years ago)
  • wp-includes/post.php

     
    17091709function wp_unique_post_slug($slug, $post_ID, $post_status, $post_type, $post_parent) {
    17101710        global $wpdb, $wp_rewrite;
    17111711        if ( !in_array( $post_status, array( 'draft', 'pending' ) ) ) {
    1712                 $post_name_check = $wpdb->get_var($wpdb->prepare("SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d AND post_parent = %d LIMIT 1", $slug, $post_type, $post_ID, $post_parent));
     1712                if ( $post_type == 'page' ) {
     1713                        $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";
     1714                } else {
     1715                        $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d AND post_parent = %d LIMIT 1";
     1716                }
     1717                $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_type, $post_ID, $post_parent));
    17131718
    17141719                if ($post_name_check || in_array($slug, $wp_rewrite->feeds) ) {
    17151720                        $suffix = 2;
    17161721                        do {
    17171722                                $alt_post_name = substr($slug, 0, 200-(strlen($suffix)+1)). "-$suffix";
    1718                                 $post_name_check = $wpdb->get_var($wpdb->prepare("SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d AND post_parent = %d LIMIT 1", $alt_post_name, $post_type, $post_ID, $post_parent));
     1723                                $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_type, $post_ID, $post_parent));
    17191724                                $suffix++;
    17201725                        } while ($post_name_check);
    17211726                        $slug = $alt_post_name;