| 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)); |
| | 1744 | $hierarchical_post_types = apply_filters('hierarchical_post_types', array('page')); |
| | 1745 | if ( 'attachment' == $post_type ) { |
| | 1746 | // Attachment slugs must be unique across all types. |
| | 1747 | $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND ID != %d LIMIT 1"; |
| | 1748 | $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_ID)); |
| | 1749 | |
| | 1750 | if ( $post_name_check || in_array($slug, $wp_rewrite->feeds) ) { |
| | 1751 | $suffix = 2; |
| | 1752 | do { |
| | 1753 | $alt_post_name = substr($slug, 0, 200-(strlen($suffix)+1)). "-$suffix"; |
| | 1754 | $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_ID)); |
| | 1755 | $suffix++; |
| | 1756 | } while ($post_name_check); |
| | 1757 | $slug = $alt_post_name; |
| 1750 | | |
| | 1759 | } elseif ( in_array($post_type, $hierarchical_post_types) ) { |
| | 1760 | // Page slugs must be unique within their own trees. Pages are in a |
| | 1761 | // separate namespace than posts so page slugs are allowed to overlap post slugs. |
| | 1762 | $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"; |
| | 1763 | $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_ID, $post_parent)); |
| | 1764 | |
| | 1774 | } else { |
| | 1775 | // Post slugs must be unique across all posts. |
| | 1776 | $check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type = %s AND ID != %d LIMIT 1"; |
| | 1777 | $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $slug, $post_type, $post_ID)); |
| | 1778 | |
| | 1779 | if ( $post_name_check || in_array($slug, $wp_rewrite->feeds) ) { |
| | 1780 | $suffix = 2; |
| | 1781 | do { |
| | 1782 | $alt_post_name = substr($slug, 0, 200-(strlen($suffix)+1)). "-$suffix"; |
| | 1783 | $post_name_check = $wpdb->get_var($wpdb->prepare($check_sql, $alt_post_name, $post_type, $post_ID)); |
| | 1784 | $suffix++; |
| | 1785 | } while ($post_name_check); |
| | 1786 | $slug = $alt_post_name; |
| | 1787 | } |