Press "Enter" to skip to content

How to update wordpress database after switching domain

WPExpert 0

Please keep backup before doing any update in database.

So this is very import to know, how to update database after moving wordpress website from one domain to another. For example

Suppose that in you are working on local server and after completion of project, you have uploaded all files on your live server along with local server database. Then here you need to run some query to update old url with new url.

Old url =

New ulr =

Now here is some query to update old url with new url

Change Siteurl & Homeurl

If you transfer your WordPress site from the localhost to your server, your site will not load online, because the absolute path URL is still pointing to your localhost server. You will need to change the site URL and the home URL.

UPDATE wp_options SET option_value = replace(option_value, '', '') WHERE option_name = 'home' OR option_name = 'siteurl';

Change GUID

After you have migrated your website from the localhost to your server or from old domain to a new domain, then you will need to fix the URLs for the GUID field in wp_posts table. This is crucial because GUID is used to translate your post or page slug to the correct article absolute path if it is entered wrongly.

UPDATE wp_posts SET guid = REPLACE (guid, '', '');

Change URL in Content

WordPress uses absolute path in the URL link instead of a relative path in the URL link when saving them into the database. Therefore you will need to change all old URLs to the new domain url.

UPDATE wp_posts SET post_content = REPLACE (post_content, '', '');

Change Image Path Only

If you decide to use Amazon CloudFront as your Content Delivery Network (CDN) to offload the delivery of images from your server. After your have created your CNAME record, you can use the query below to change all the image paths in WordPress to load all your images from Amazon CloudFront.

wp_posts SET post_content = REPLACE (post_content, 'src="', 'src="');

You will also need to update the GUID for Image Attachment with the following query:

UPDATE wp_posts SET guid = REPLACE (guid, '', '') WHERE post_type = 'attachment';

Update Post Meta

Okay so here is updating post meta works almost the same way as updating the URL in post content. If you have stored extra URL data for each post, then you can use the follow query to change all of them.

UPDATE wp_postmeta SET meta_value = REPLACE (meta_value, '','');


Leave a Reply

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