From e9142f3f050f7ed3b42028dece5466b738505841 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Thu, 30 Nov 2006 23:09:27 +0000 Subject: [PATCH] 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 --- wp-includes/post.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/wp-includes/post.php b/wp-includes/post.php index 4a844554d0..bea12cff66 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -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))