WordPress.org

Make WordPress Core

Ticket #2421: post_name_uniqueness_specificity.diff

File post_name_uniqueness_specificity.diff, 1.9 KB (added by markjaquith, 9 years ago)

Uniqueness based on current permalink structure

  • wp-includes/functions-post.php

     
    105105                $post_password = ''; 
    106106 
    107107        if ( 'draft' != $post_status ) { 
    108                 $post_name_check = $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$post_name' AND post_type = '$post_type' AND ID != '$post_ID' AND post_parent = '$post_parent' LIMIT 1"); 
     108                if ( 'page' != $post_type ) { 
     109                        $pls = get_settings('permalink_structure'); 
     110                        if ( strpos($pls, '%day%') !== false ) 
     111                                $specificity = " AND YEAR(post_date) = YEAR('$post_date') AND MONTH(post_date) = MONTH('$post_date') AND DAYOFMONTH(post_date) = DAYOFMONTH('$post_date') "; 
     112                        elseif ( strpos($pls, '%monthnum%') !== false ) 
     113                                $specificity = " AND YEAR(post_date) = YEAR('$post_date') AND MONTH(post_date) = MONTH('$post_date') "; 
     114                        elseif ( strpos($pls, '%year%') !== false ) 
     115                                $specificity = " AND YEAR(post_date) = YEAR('$post_date') "; 
     116                        else 
     117                                $specificity = ""; // this could be for people without a fancy permalink structure or people just using %postname% 
     118                } 
     119                $post_name_check = $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$post_name' AND post_type = '$post_type' AND ID != '$post_ID' AND post_parent = '$post_parent' $specificity LIMIT 1"); 
    109120 
    110121                if ($post_name_check) { 
    111122                        $suffix = 2; 
    112123                        while ($post_name_check) { 
    113124                                $alt_post_name = $post_name . "-$suffix"; 
    114                                 $post_name_check = $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$alt_post_name' AND post_type = '$post_type' AND ID != '$post_ID' AND post_parent = '$post_parent' LIMIT 1"); 
     125                                $post_name_check = $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$alt_post_name' AND post_type = '$post_type' AND ID != '$post_ID' AND post_parent = '$post_parent' $specificity LIMIT 1"); 
    115126                                $suffix++; 
    116127                        } 
    117128                        $post_name = $alt_post_name;