WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I generate XML file with [Tools > Export] and use [Tools > Import] on another WordPress website I get "Failed to import Media" for each attachment post type. And images that failed to load are hotlinked from the previous server which consumes the transfer of that previous server...

But when I download "Unit Test" from http://codex.wordpress.org/Theme_Unit_Test then this problem doesn't exist. Some images still have "Failed to import Media" but it's only like 5 out of 30 images. They have URLs to their own server in their XML but somehow [Tools > Import] manages to download their media and replace these URLs with new locations (it is not hotlinked anymore).

What's the trick to make it work properly without "Failed to import Media"? Why even "Unit Test" has a few "Failed to import Media" messages?

share|improve this question
As the server where you import needs to get them from the old location you should not only check if the files are at the old server, but also if the new server can fetch them. Maybe something limits outbound requests. Have you tried importing it on another server or localhost? I am afraid this could be a very localised issue. – kraftner Jun 6 '14 at 15:49
As of WordPress 4.3.1 (possibly earlier) you can define IMPORT_DEBUG and set it to true to get meaningful feedback instead of just "Failed to import media". I can't imagine why this isn't default behavior. That may help narrow your problem down if the weather is just right. – Mark Oct 19 '15 at 20:40
@Mark in which file can I set the IMPORT_DEBUGoption – kimliv Jun 11 at 9:34
@kimliv: you'll want to stick this in wp-config.php at the root of your WordPress install: define ( 'IMPORT_DEBUG', true );. – Mark Jun 12 at 12:40

I had a very similar problem when I moved a WordPress Blog from a single WordPress installation to a Multisite installation with different domain names but same IP.
I found out that the problem is the wp_http_validate_url function which drops the URL if the source IP is the same as the destination IP.
You can add a filter wp_http_validate_url to prevent this and allow matching source and destination IPs:

add_filter( 'http_request_host_is_external', '__return_true' );

Please see this answer for detailed explanation of the filter hook and why you should remove it after the import: http://wordpress.stackexchange.com/a/123313/75573

share|improve this answer
You, are a godsend. Thank you! – Michelle 21 hours ago

When you generated your export file, was it on a live server or a localhost? Is that web page still accessable? If the media import fails, it means the images, as linked out of the XML, are coming up 404.

Open up the XML file and see where the images are pointing. If we open up the Theme Unit XML file, we will see lines like this:


That file is very clearly available for import. What do your attachment_url files say?

share|improve this answer
I mentioned "And images that failed to load are hotlinked from the previous server which consumes the transfer of that previous server..." which indicates that images do not return 404, they are not on localhost but they still generate "Failed to import Media". My <wp:attachment_url> says example.com/2008/06/image.jpg too where example.com is always accessible domain. That's why I'm asking this question :) It clearly doesn't work even if images do not generate 404. It even doesn't work with wpthemetestdata.files.wordpress.com occasionally (~5 random images out of 30 fail). – Paul Oct 10 '13 at 7:53
Right, sorry, my mind is a bit burned out at this point in the night. Do you have some kind of hotlink protection on the server? – Imperative Ideas Oct 10 '13 at 8:19
Nope, it's publicly accessible server with publicly accessible images, no protection whatsoever. But even if there was some protection, WordPress's server does the same thing occasionally. Does it mean that this importer is just buggy? – Paul Oct 10 '13 at 8:35
That or one of the servers has an obnoxiously short timeout value. I'm fresh out of ideas for you. Does the XML import properly to Localhost? If so, you can sort of cheat... do the import locally then use WP Migrate DB and clone the result to live. – Imperative Ideas Oct 10 '13 at 8:57

I've been struggling with importing media to wordpress.org from wordpress.com as well. I managed to import all posts however images were still linked to the old site. I was nearly crying as I realised the only solution was to manually download and upload over 200 large images post by post (exporting/importing smaller portions of posts didn't work either).

After testing some plugins I found one that actually imports your wordpress media automatically. I couldn't believe but it actually does work. You have to go post by post but still it's better than manual download and upload. Here is the link if anyone is interested

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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