From 97bf1f11bdbba3e88b7a7b60763901efa323029d Mon Sep 17 00:00:00 2001 From: ryan Date: Mon, 30 Nov 2009 21:41:52 +0000 Subject: [PATCH] Save parent temp ID for unattached attachments in postmeta. Props scribu. fixes #9471 git-svn-id: http://svn.automattic.com/wordpress/trunk@12298 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/post.php | 12 +++++++++++- wp-includes/post.php | 3 +++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/wp-admin/includes/post.php b/wp-admin/includes/post.php index 588bc5089..e611287dc 100644 --- a/wp-admin/includes/post.php +++ b/wp-admin/includes/post.php @@ -773,7 +773,17 @@ function _relocate_children( $old_ID, $new_ID ) { global $wpdb; $old_ID = (int) $old_ID; $new_ID = (int) $new_ID; - return $wpdb->update($wpdb->posts, array('post_parent' => $new_ID), array('post_parent' => $old_ID) ); + + $children = $wpdb->get_col( $wpdb->prepare(" + SELECT post_id + FROM $wpdb->postmeta + WHERE meta_key = '_wp_attachment_temp_parent' + AND meta_value = %d", $old_ID) ); + + foreach ( $children as $child_id ) { + $wpdb->update($wpdb->posts, array('post_parent' => $new_ID), array('ID' => $child_id) ); + delete_post_meta($child_id, '_wp_attachment_temp_parent'); + } } /** diff --git a/wp-includes/post.php b/wp-includes/post.php index 3110ba4c6..271d0dd56 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -2804,6 +2804,9 @@ function wp_insert_attachment($object, $file = false, $parent = 0) { clean_post_cache($post_ID); + if ( isset($post_parent) && $post_parent < 0 ) + add_post_meta($post_ID, '_wp_attachment_temp_parent', $post_parent, true); + if ( $update) { do_action('edit_attachment', $post_ID); } else {