Make sure multiple attachments for the same post have unique permalinks. Props filosofo. fixes #3033
git-svn-id: https://develop.svn.wordpress.org/trunk@4561 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
c539a41672
commit
e9142f3f05
|
@ -1242,6 +1242,19 @@ function wp_insert_attachment($object, $file = false, $post_parent = 0) {
|
|||
else
|
||||
$post_name = sanitize_title($post_name);
|
||||
|
||||
$post_name_check =
|
||||
$wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$post_name' AND post_status = 'inherit' AND ID != '$post_ID' LIMIT 1");
|
||||
|
||||
if ($post_name_check) {
|
||||
$suffix = 2;
|
||||
while ($post_name_check) {
|
||||
$alt_post_name = $post_name . "-$suffix";
|
||||
$post_name_check = $wpdb->get_var("SELECT post_name FROM $wpdb->posts WHERE post_name = '$alt_post_name' AND post_status = 'inherit' AND ID != '$post_ID' AND post_parent = '$post_parent' LIMIT 1");
|
||||
$suffix++;
|
||||
}
|
||||
$post_name = $alt_post_name;
|
||||
}
|
||||
|
||||
if (empty($post_date))
|
||||
$post_date = current_time('mysql');
|
||||
if (empty($post_date_gmt))
|
||||
|
|
Loading…
Reference in New Issue