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?
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: https://wordpress.stackexchange.com/a/123313/75573
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?
Make sure your site isn’t set to “Private”.
When you export your WordPress blog, all the textual content is embedded in the resulting XML file. All the binary content (pictures, file attachments etc) are exported as URLs pointing to their location on the existing blog. This is why when you import from a private WordPress blog you will still be able to import all the posts/etc but all the images/etc will fail.
Here is where you need to change the setting as of the curent (2017-06-19) version:
Relevant WordPress documentation:
Note that it needs to be done from your WordPress.com account’s settings, not from the settings of the blog itself, which is another potential point of confusion (and frustration).
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