| 1741 | | if ( !in_array( $post_status, array( 'draft', 'pending' ) ) ) { |
| 1742 | | $hierarchical_post_types = apply_filters('hierarchical_post_types', array('page', 'attachment')); |
| 1743 | | if ( in_array($post_type, $hierarchical_post_types) ) { |
| 1744 | | $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( '" . implode("', '", $wpdb->escape($hierarchical_post_types)) . "' ) AND ID != %d AND post_parent = %d LIMIT 1"; |
| 1745 | | $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_ID, $post_parent)); |
| 1746 | | } else { |
| 1747 | | $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"; |
| 1748 | | $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_type, $post_ID, $post_parent)); |
| 1749 | | } |
| 1751 | | if ( $post_name_check || in_array($slug, $wp_rewrite->feeds) ) { |
| 1752 | | $suffix = 2; |
| 1753 | | do { |
| 1754 | | $alt_post_name = substr($slug, 0, 200-(strlen($suffix)+1)). "-$suffix"; |
| 1755 | | $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_type, $post_ID, $post_parent)); |
| 1756 | | $suffix++; |
| 1757 | | } while ($post_name_check); |
| 1758 | | $slug = $alt_post_name; |
| 1759 | | } |
| | 1742 | if ( in_array( $post_status, array( 'draft', 'pending' ) ) ) |
| | 1743 | return $slug; |
| | 1744 | |
| | 1745 | $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type != 'revision' AND post_status != 'draft' AND ID != %d LIMIT 1"; |
| | 1746 | $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_ID)); |
| | 1747 | |
| | 1748 | if ( $post_name_check || in_array($slug, $wp_rewrite->feeds) ) { |
| | 1749 | $suffix = 2; |
| | 1750 | do { |
| | 1751 | $alt_post_name = substr($slug, 0, 200-(strlen($suffix)+1)). "-$suffix"; |
| | 1752 | $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_ID)); |
| | 1753 | $suffix++; |
| | 1754 | } while ($post_name_check); |
| | 1755 | $slug = $alt_post_name; |