[WordPress] – Update image links when moving site

I needed to move a customer’s domain to a new location and that meant updating the image links, since wordpress uses absolute URLs.  Fortunately there is an easy fix for this, MySQL to the rescue!

There are 3 different SQL queries you need to make (use PHPMyAdmin, CommandLine or just write a PHP script to run).

The first one fixes all the wordpress options in the wp_options table

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';

*only replace the old-domain and new-domain.

The second query will update guids in table wp_posts

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

And finally we update the post_content of table wp_posts

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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>