I've set up a dev site for a client, for who we're overhauling their existing site.

One thing I wanted to do is import all their existing news posts, and carry over any images attached to those. I've managed to export the attachments WP Attachment Export plugin. The xml file appears to be all fine, and the correct values for post_parent are included.

When I try to import the xml file using the standard Wordpress Importer - the images are imported into the media library, and the various data that goes with it except all the post_parent values are reset to 0, meaning that they're no longer attached to anything.

What's going on here, and is there a work around to have the post_parent imported properly? The existing site has over a thousand media files, so clearly I don't want to have to re-attach them manually.

Edit. Here is a sample of one of the attachments in the xml. I've xxxx out some of filename/titles.

    <pubDate>Wed, 18 Sep 2013 04:00:21 +0000</pubDate>
    <guid isPermaLink="false">http://www.xxxxxxx.com/wp-content/uploads/2013/09/xxxxxxx.jpg</guid>
    <wp:post_date>2013-09-18 13:30:21</wp:post_date>
    <wp:post_date_gmt>2013-09-18 04:00:21</wp:post_date_gmt>


  • Please link to the plugin you have used. Also why have you used plugin in first place? Native WordPress export should have no issues with attachments.
    – Rarst
    Commented Sep 19, 2013 at 13:19
  • Hi @Rarst, the plugin I used was wordpress.org/plugins/wp-attachment-export, as the normal Wordpress Export doesn't export attachments, only other post types. It's largely irrelevant though, I have the xml export file, and the values are correct there. The issue is importing the file, that the post_parent values are being reset to 0.
    – Nathan
    Commented Sep 20, 2013 at 0:22
  • Native export works with attachments just fine, what are you basing that it doesn't on? Please include short sample of your export on which issue can be reproduced.
    – Rarst
    Commented Sep 20, 2013 at 10:08
  • There is no way to just export attachments via the native export, only via the export all content (which I don't want, as there are pages and custom post types I don't intend to copy over). The xml output by the plugin is identical to what the native export puts out, and there appears to be nothing wrong with the data in the xml file. I've added a sample of one entry in the export. Everything there is correct. After importing, everything is imported correctly, except the post_parent value (in this case 3874), which if I check the database, shows up as 0.
    – Nathan
    Commented Sep 21, 2013 at 12:47
  • I should add, that the posts that they are attached to, do exist, and do have the same post_id.
    – Nathan
    Commented Sep 21, 2013 at 12:48

2 Answers 2


I think that importing attachments separately (which is not possible with native export) is precisely cause for your issue. Importer plugin has following code:

if ( $post_parent ) { 
    // if we already know the parent, map it to the new local ID
    if ( isset( $this->processed_posts[$post_parent] ) ) {    
        $post_parent = $this->processed_posts[$post_parent];
    // otherwise record the parent for later
    } else {
        $this->post_orphans[intval($post['post_id'])] = $post_parent;
        $post_parent = 0;

There is some more processing with orphans, but in a nutshell it seems that only posts in same import are being considered for parent. Which kind of make sense, since IDs at the time of export are not guaranteed to be precisely same as IDs at the time of import.

  • You may be right. I decided to give exporting and importing the whole lot, but unfortunately that dies on me (client has uploaded 1100+ images to the original site, and the import just gives up half way through). Guess that's a good excuse to tell them to "start fresh". Thanks for your help.
    – Nathan
    Commented Sep 23, 2013 at 2:20

Check the size of the image is not so great , I had a problem importing and after much review and import I realized that the image where the import stopped weighed some 16mb , I guess exceed the maximum execution time or something similar on the server.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.