diff --git a/wp-admin/includes/media.php b/wp-admin/includes/media.php
index 87ac47f0be..0062d4d8db 100644
--- a/wp-admin/includes/media.php
+++ b/wp-admin/includes/media.php
@@ -372,6 +372,8 @@ function media_upload_form_handler() {
$post['post_excerpt'] = $attachment['post_excerpt'];
if ( isset($attachment['menu_order']) )
$post['menu_order'] = $attachment['menu_order'];
+ if ( isset($attachment['post_parent']) )
+ $post['post_parent'] = $attachment['post_parent'];
$post = apply_filters('attachment_fields_to_save', $post, $attachment);
@@ -1185,6 +1187,13 @@ function get_media_item( $attachment_id, $args = null ) {
foreach ( $hidden_fields as $name => $value )
$item .= "\t\n";
+ if ( $post->post_parent < 1 && (int) $_REQUEST['post_id'] ) {
+ $parent = (int) $_REQUEST['post_id'];
+ $parent_name = "attachments[$attachment_id][post_parent]";
+
+ $item .= "\t\n";
+ }
+
return $item;
}