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.