Title: Attachment Parent
Last modified: August 18, 2016

---

# Attachment Parent

 *  [andreineculau](https://wordpress.org/support/users/andreineculau/)
 * (@andreineculau)
 * [19 years, 2 months ago](https://wordpress.org/support/topic/attachment-parent/)
 * You start to “Write [a new] Page”. You put in a title, add some text… then you“
   Upload” a file and send it to the editor.
    You “Publish” your newly created page.
 * The attachment has -xxxxxxx as post_parent.
    Isn’t that weird?!
 * I’m using WordPress as a secondary interface, and linkage is essential (I need
   to see what files have been uploaded/attached to each and every post).
 * Why isn’t post_parent update let’s say.. upon sending it to editor, in case it
   doesn’t already have a parent?? Or even upon saving the current post??
 * Why do I have to write a title… then Save, then Upload, then write the text?!

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [wonkavator](https://wordpress.org/support/users/wonkavator/)
 * (@wonkavator)
 * [18 years, 11 months ago](https://wordpress.org/support/topic/attachment-parent/#post-543398)
 * Bumping this topic up because I just encountered the same thing in WP 2.2.1.
 * I have some code that takes a post, looks to see if it has children of type ‘
   attachment’ and then does stuff with it. This means that the post_parent relationship
   between an uploaded file and the post it was uploaded to is very important to
   the success of my code.
 * However, I have noticed that I can successfully ‘attach’ a file to a post by 
   uploading it. However, if I go back to that file (in the Browse tab of the parent
   post) and edit its Title or Description, suddenly the connection between the 
   attachment and the parent post is gone. I checked the database and the post_parent
   field for the attachment post is set to 0 instead of the correct post_parent 
   id.
 * So it seems that the initial upload correctly sets the post_parent for the attachment
   post, but any subsequent changes breaks it. Can we have a fix in the next patch?
 * As for temporary solutions, I’m considering using a Hook/Filter approach if possible.
 *  [ianjohn27](https://wordpress.org/support/users/ianjohn27/)
 * (@ianjohn27)
 * [18 years, 11 months ago](https://wordpress.org/support/topic/attachment-parent/#post-543401)
 * I’m having this same issue, and as with wonkavator, this is a very important 
   feature for a lot of my custom code — the parent/child relationship has to be
   maintained. Any help with this greatly appreciated.
 *  [ianjohn27](https://wordpress.org/support/users/ianjohn27/)
 * (@ianjohn27)
 * [18 years, 11 months ago](https://wordpress.org/support/topic/attachment-parent/#post-543402)
 * I have a solution that seems to work fine for this. I haven’t tested it too heavily.
 * in wp-includes/post.php
    look for function wp_update_post on line 747 (for me,
   wp v. 2.2.1) you’ll see this:
 * if ($postarr[‘post_type’] == ‘attachment’)
    return wp_insert_attachment($postarr);
 * change to this:
 * if ($postarr[‘post_type’] == ‘attachment’)
    return wp_insert_attachment($postarr,
   false, $post[‘post_parent’]);
 * hope this helps!
 *  [ladamiak](https://wordpress.org/support/users/ladamiak/)
 * (@ladamiak)
 * [18 years, 10 months ago](https://wordpress.org/support/topic/attachment-parent/#post-543411)
 * Hey..
 * Grate… That fixed my problems.
 * Thx.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Attachment Parent’ is closed to new replies.

## Tags

 * [attachment](https://wordpress.org/support/topic-tag/attachment/)
 * [parent](https://wordpress.org/support/topic-tag/parent/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 4 participants
 * Last reply from: [ladamiak](https://wordpress.org/support/users/ladamiak/)
 * Last activity: [18 years, 10 months ago](https://wordpress.org/support/topic/attachment-parent/#post-543411)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
