Home » Wordpress » How do I bulk upload images coming from an old, defunct wordpress site to a new wordpress site?

How do I bulk upload images coming from an old, defunct wordpress site to a new wordpress site?

Posted by: admin November 30, 2017 Leave a comment

Questions:

Here is the situation: some friends had an old web site with wordpress running on it, and lost the domain name and hosting account through some shenanigans we won’t discuss here. I have a full backup of their site, including a wordpress export file in XML.

I can easily create a completely new wordpress installation on their new server, using the export file to import all their posts into the database.

The problem is here: I can’t use the importer to pull over the images and attachments using that XML file, because the links are incorrectly pointing to the now non-existant old site. I have the images and attachments, but now I’m wondering how can I bulk upload them into the new database’s media library and maintain, or update, the links to them properly?

Scanning the wordpress support site and looking through the plugins list yields far too many hits that have nothing to do with what I am trying to accomplish.

I’ve tried modifying the export XML file to tell it to pull files from a local drive instead of the old host, by modifying attachment posts’ <wp:attachment_url> entry, but this did not work. If someone knows what particular field the wordpress-importer is using, that would be quite a help, I think.

Answers:

This will work only if , like you stated in your question – you have the FULL BACKUP of the site ( files AND database )

1 – FTP Put all the original wp folder structure from OLD site into NEW server as – is .

2 – login to phpmyadmin and import the OLD database .

3 – run SQL like so :

/**
To update WordPress options with the new blog location, use the following SQL command:
**/

UPDATE wp_options SET option_value = replace(option_value, 'http://www.old-domain.com', 'http://www.new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';

/**
After that you will need to fix URLs of the WordPress posts and pages, which translated from post slug, and stored in database wp_posts table as guid field. The URL values in this field are stored as abolute URLs instead of relative URLs, so it needs to be changed with the following SQL query:
**/

UPDATE wp_posts SET guid = replace(guid, 'http://www.old-domain.com','http://www.new-domain.com');

/**
If you have linked internally within blog posts or pages with absolute URLs, these links will point to wrong locations after you move the blog location. Use the following SQL commands to fix all internal links to own blog in all WordPress posts and pages:
**/

UPDATE wp_posts SET post_content = replace(post_content, 'http://www.old-domain.com', 'http://www.new-domain.com');

Later , Just to verify , go to the wp_options ( or prefix_options ) table and search for home_url and blog_url options – and see if they are accordingly change ( this depends on DB version )

If all is ok and done correctly – you now can log in to your new domain..

BTW – If you have files and DB on local machine , you can run the changes, export and import to the DB already changed .. ( which is how I usually do it almost on a daily basis – a bit more time but fool proof )

If you do all the above correctly , and you did have the ORIGINAL DB and files exactly from before – you will have a new working copy on the new domain .

Basically, if you do that correctly , there is no need to “import” any images . you will be performing a simple move of domain for the whole site, including plugins, content, images, settings, themes and what not ..

Note on upgrades / version: when I wrote “original” wp folder structure I meant just that . even if it an old wp version and old plugins / themes – first do those steps above , and only then run an upgrade . Do not put a new wp version unless you know the old one is db compatible …