I’ve worked with several versions of WordPress, to different purposes at each time. One thing that happens often is having to move WordPress from one domain to another… It’s not enough just to copy the files to the new domain and connect the new database with the backup of the previous one.
After doing your file and database backups, and putting them on your new domain, you will need to run the queries below:
1 2 3 4 5 6 7 |
UPDATE wp_options SET option_value = REPLACE(option_value, 'http://www.oldsiteurl.com', 'http://www.newsiteurl.com') WHERE option_name = 'home' OR option_name = 'siteurl'; UPDATE wp_posts SET guid = REPLACE(guid, 'http://www.oldsiteurl.com', 'http://www.newsiteurl.com'); UPDATE wp_posts SET post_content = REPLACE(post_content, 'http://www.oldsiteurl.com', 'http://www.newsiteurl.com'); UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'http://www.oldsiteurl.com','http://www.newsiteurl.com'); |
Suppose that your domain was potatoes.com and now it’s onions.com. You will have to execute what follows:
1 2 3 4 5 6 7 |
UPDATE wp_options SET option_value = REPLACE(option_value, 'http://www.potatoes.com', 'http://www.onions.com') WHERE option_name = 'home' OR option_name = 'siteurl'; UPDATE wp_posts SET guid = REPLACE(guid, 'http://www.potatoes.com', 'http://www.onions.com'); UPDATE wp_posts SET post_content = REPLACE(post_content, 'http://www.potatoes.com', 'http://www.onions.com'); UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'http://www.potatoes.com', 'http://www.onions.com'); |
After that, your WordPress will keep working on the new domain! This method works since version 3, and at the time of writing this post, we’re on version 4.4.