WordPress Database Query
Please note, that this article is intended for WordPress beginners and aims to provide guidance to those who have not dealt much with WordPress site migration.
Installing WordPress is very easy and can be done in 5 steps whether you are on your local server or a live server. You can accomplish this without going through any trouble.
Now, suppose you are developing an application using WordPress and you are developing on your local machine. You are starting from scratch WordPress install. You install your WordPress and start to develop your website.
It may take a while but then you complete and decide to shift it to live. So, you research on things and know how to migrate your WordPress site. So, you zip your source code and upload it to your cpanel and unzip your files.
Finally, you import your database and all seems to work out. You change your options file in database and check your site in live and your site is totally broken.
So, when you access your site your site is totally broken. Images don’t show up and styles are totally messed. When you look at your inspect code from browser you see localhost all over.
One would wonder if they have not handled site migration in WordPress. What might have gone wrong and you end up punching yourself. When you migrate your WordPress site using this method you will always need to update your database options. So, i have made a simple database query that will update all your tables as a whole. It will update all your old links to new links.
UPDATE wp_options SET option_value = replace(option_value, 'http://youroldsite.com', 'http://newdomain.com'); UPDATE wp_posts SET guid = replace(guid, 'http://youroldsite.com', 'http://newdomain.com'); UPDATE wp_posts SET post_content = replace(post_content, 'http://youroldsite.com', 'http://newdomain.com'); UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://youroldsite.com','http://newdomain.com');
Running the above query will update all the values. Paste your old site url in place of “http://youroldsite.com” and place your new site url in place of “http://newdomain.com”.
Check your site after you run this query and see that your site should run properly now. Note: if you are using any visual editors on your site then there might be chance that you will have to update your links if you have uploaded any images from there.
The Most Easiest Solution for Site Migration in WordPress
There is even a better solution for the site migration. There is a plugin called Duplicator.
This plugin might be little confusing to use but is way better for any site migration in WordPress. With just few clicks you can zip your source code and get your database. The plugin makes installer file for you and you simply have to upload them and run the installer file and configure few details and your site is migrated. You won’t have to deal with any problems.
Check this out here.