WordPress Importer not importing Attachments? Try exporting All Statuses!

Ever tried to export content from a WordPress site and then import it to another with the WordPress Importer only to find the attachments were not imported? You are not alone. I just spent a couple of hours troubleshooting the issue and I made a very interesting, if perplexing, discovery that may solve your problem.

First a little back story. Of the many things that drive people crazy and induces a burning desire to take the application for a spin in a blender is the WordPress Importer. To say the plugin is rife with problems would be an understatement. A simple Google search will show you that the importer not importing attachments is a problem that has been around for years and has yet to be dealt with properly. Not impressive in the least. Now let’s get to the point of my story.

The Problem

Here’s the scenario: Site 1 has 900+ posts of which about 800 have already been moved to Site 2 by porting the database. Now the new posts (about 100) need to be ported over using the importer. Because there are about 30 draft posts in Site 1 that have already been ported, I wanted to ignore these so in the exporter under Statuses I selected “Published”.

Run the importer and all the posts are imported but the image and attachment links are all pointing back to Site 1. Not what I want.

So I do some tinkering with the import file, move the files manually, and generally mess around with everything. This has worked in the past, but for some unexplainable reason it doesn’t work now. The attachments are not being imported.

The Solution (which makes no sense)

So, after banging my head against the keyboard for a while I decided to try something different: Instead of setting Statuses to “Published” I set it to the default “All Statuses”. The xml file appears, I import it, and behold: The attachments are imported!

The Reason (which makes even less sense)

Comparing the two export files one thing becomes immediately obvious: In the first file – in which I specified I only wanted Published statuses, the attachments are referenced in the posts, but the attachment table is ignored. In the second file – in which I exported All Statuses – the attachment table is included. In other words the WordPress export function defines Attachment posts as something other than Published. Which of course is rubbish, but whatever.

So, if you are having problems getting your attachments to import, try setting Statuses to All Statuses when you export and maybe, just maybe, you’ll get WordPress to do what you want.


About Morten Rand-Hendriksen

Morten Rand-Hendriksen is a staff author at lynda.com specializing in WordPress and web design and development and an instructor at Emily Carr University of Art and Design. He is a popular speaker and educator on all things design, web standards and open source. As the owner and Web Head at Pink & Yellow Media, a boutique style digital media company in Burnaby, BC, Canada, he has created WordPress-based web solutions for multi-national companies, political parties, banks, and small businesses and bloggers alike. He also contributes to the local WordPress community by organizing Meetups and WordCamps.

11 comments:

  1. This may help understand the crazy somewhat…

    Attachments have the post_status of “inherit” which makes perfect sense if you assume that every attachment is associated with a post. By doing this, WP saves some work on every save. It doesn’t have to check ‘Post is scheduled. Okay, let’s get all the attachments and update them.’ and it doesn’t have to update all the pages when it publishes, deletes, etc.

    Of course, you have caught the fatal flaw of this, though. The importer is too precise.

    1. From a WordPress core / developer standpoint it makes sense that this is what happening, but from a user standpoint it is counterintuitive and in contradiction to expected behaviour. The plugin needs to be updated to not apply the post_status value to the Attachments or to treat Attachments as a separate entity. I doubt anyone would ever intend to export all published posts and pages without also exporting the attachments.

      1. In my perception, it is always about: Expected behavior
        It’s the user how uses the software, and it should behave as expected If not it is just Broken

        It maybe is not in the eye of the developer, but that doesn’t matter it is in the eye of the user. This is one of the key issues that Steve Jobs addressed with “We make the best possible user expressions”

        This is a way of working the WordPress community as a whole and the core team in particular can learn a lot from.

        WordPress kind of sucks. It’s a pity, but a lot of things are kind of broken we learned to live with it as they don’t get addressed by the core team as they are not focusing on what users really need. Best possible user expressions as in: Expected behavior

        Fortunately WordPress sucks less than a lot of other Opensource CMS / blog systems. :-) I still love the community way how things are getting build and fixed.

        But somehow, wouldn’t it be great to become great?

        Stop being just code developers point of view. Become the best possible user expressions. Don’t fix what is not broken, fix what is not expected behavior, cause that is really what is broken.

  2. OMG the #%&(#$&%(*$# WordPress Importer!!! If I bail on WP for Ghost or any other platform, the Importer will be Reason #1. I have lost so much content and so many wrist-slitting hours of frustration. How can this have been so dysfunctional for so long? Every time it doesn’t work I have to ask if I’m the only person who ever moves a site? Or if everyone else knows the “real” way to do it without the importer. I literally have years of broken links thanks to the importer. We’d be better served if it didn’t exist at all.

    kk, haha, I guess that wasn’t really about YOUR post! But the importer has so frustrated my life that I can’t pass even the slightest opportunity to vent. On forums if you get a reply at all, peeps seem surprised that there’s any trouble with this “easy to use tool.” So besides a possible solution your post suggests that I’m not *totally* crazy.

    haha, I should just stop already. You’ve roused too much anger and frustration for me to speak clearly. Anyway, I’d pretty much decided to restructure my work flow so that I NEVER move a site. Once you rent server space, it’s a commitment to use that host forever. Maybe the “hosting cartel” wrote the Importer?? Yes, the Importer definitely brings out dreams of conspiracy theories.

    Anyway, THANK YOU for anything that might help next time I have to move content, if I’m masochistic enough to ever try again. :P

  3. WordPress needs to clean up the attachment concept. Actually get rid of it. Well it has sort of already. Just deprecate it.

    With custom posts – and attachments are now defined as a custom post – treat them that way and get rid of inheritance. Attachments aren’t digital DNA!

  4. I cannot believe this!!! Thanks for the post, i was banging my head around the same issue (imported only a taxonomy instead of the entire blog).

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>