Replace Old To New Url In The WordPress Database

If you are new in WordPress development and working on a client project then one thing you have to take note is that whenever you deploy your WordPress project to client-server you have to replace your site URL from local to live and the same thing will apply, If you migrate from one to another domain. If you forgot to change URL then it will redirect to the old URL and that needs to take care of it.

Another way you can avoid this problem by creating a virtual host in your local server with a live domain.

replace old to new url in the wordpress database

So how to replace old to new URL in the WordPress database? Well, it’s very easy. You just have to replace your old URL with the new URL so follow the below steps.

Step 1:

If you have already uploaded the database to the server, then go to your phpMyAdmin and open your database.

Step 2:

Copy the below code and replace your old URL with and do the same for the new URL.

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

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

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

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

After replacing your old & new URL, go to the SQL section in your phpMyAdmin and past your SQL queries and hit the Go button.

After hitting the Go button, SQL queries will replace all instances of old URLs to new URLs. For example, If your current WordPress address is, it will be changed to

IMPORTANT! Sometimes table prefix can be different than wp_. If you get error messages saying that tables wp_optionswp_postswp_posts and wp_postmeta cannot be found, check table prefix and update SQL query code. You can see table prefix on the left side of phpMyAdmin, under your WordPress database:

Step 3:

If the query was executed successfully, then you will see a green success message with the number of records is affected.

Keep visiting for new stuff and give your feedback.

Happy Coding 😉

Author: admin

Leave a Reply