Failed to import Media

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?

10

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

Leave a Comment