1

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.

<item>
    <title>XXXXXXXXXX</title>
    <link>http://www.xxxxxxx.com/news/xxxxxxx/attachment/xxxxxxx/</link>
    <pubDate>Wed, 18 Sep 2013 04:00:21 +0000</pubDate>
    <dc:creator>Emma</dc:creator>
    <guid isPermaLink="false">http://www.xxxxxxx.com/wp-content/uploads/2013/09/xxxxxxx.jpg</guid>
    <description></description>
    <content:encoded><![CDATA[]]></content:encoded>
    <excerpt:encoded><![CDATA[]]></excerpt:encoded>
    <wp:post_id>3880</wp:post_id>
    <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>
    <wp:comment_status>closed</wp:comment_status>
    <wp:ping_status>closed</wp:ping_status>
    <wp:post_name>xxxxxxx</wp:post_name>
    <wp:status>inherit</wp:status>
    <wp:post_parent>3874</wp:post_parent>
    <wp:menu_order>0</wp:menu_order>
    <wp:post_type>attachment</wp:post_type>
    <wp:post_password></wp:post_password>
    <wp:is_sticky>0</wp:is_sticky>
    <wp:attachment_url>http://www.xxxxxxx.com/wp-content/uploads/2013/09/xxxxxxx.jpg</wp:attachment_url>
    <wp:postmeta>
        <wp:meta_key>_wp_attached_file</wp:meta_key>
        <wp:meta_value><![CDATA[2013/09/xxxxxxx.jpg]]></wp:meta_value>
    </wp:postmeta>
    <wp:postmeta>
        <wp:meta_key>_wp_attachment_metadata</wp:meta_key>
        <wp:meta_value><![CDATA[a:5:{s:5:"width";i:500;s:6:"height";i:435;s:4:"file";s:30:"2013/09/xxxxxxx.jpg";s:5:"sizes";a:3:{s:9:"thumbnail";a:4:{s:4:"file";s:30:"xxxxxxx.jpg";s:5:"width";i:220;s:6:"height";i:150;s:9:"mime-type";s:10:"image/jpeg";}s:6:"medium";a:4:{s:4:"file";s:30:"xxxxxxx.jpg";s:5:"width";i:340;s:6:"height";i:295;s:9:"mime-type";s:10:"image/jpeg";}s:5:"large";a:4:{s:4:"file";s:30:"xxxxxxx.jpg";s:5:"width";i:402;s:6:"height";i:350;s:9:"mime-type";s:10:"image/jpeg";}}s:10:"image_meta";a:10:{s:8:"aperture";i:0;s:6:"credit";s:0:"";s:6:"camera";s:0:"";s:7:"caption";s:0:"";s:17:"created_timestamp";i:0;s:9:"copyright";s:0:"";s:12:"focal_length";i:0;s:3:"iso";i:0;s:13:"shutter_speed";i:0;s:5:"title";s:0:"";}}]]></wp:meta_value>
    </wp:postmeta>
</item> 

Cheers.

5
  • 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

1

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.

1
  • 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
0

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.