Back to all posts

Revamp Your Website: Effortlessly Update Your WordPress URLs with These SQL Queries

March 18, 2023 wordpress By parthmaghara@gmail.com

If you’re planning to change the URL structure of your WordPress website, you need to ensure that all the URLs are updated correctly to avoid any broken links or 404 errors. One way to do this is by using SQL queries to update the URLs in your WordPress database. In this blog, we’ll discuss the SQL queries you can use to update the URLs in your WordPress database.

Before we start, it’s important to note that making changes to your WordPress database can be risky, and it’s recommended to backup your website before proceeding with any changes.

The SQL queries you can use to update the URLs in your WordPress database are as follows:

1. Update the Site URL

The first SQL query you need to use is to update the site URL. This query updates the URLs in the “home” and “siteurl” fields in the wp_options table.

UPDATE wp_options SET option_value = replace(option_value, 'http://old-url.com/', 'http://new-url.com/') WHERE option_name = 'home' OR option_name = 'siteurl';

2. Update Post URLs

The second SQL query you need to use is to update the post URLs. This query updates the URLs in the guid and post_content fields in the wp_posts table.

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

3. Update Post Meta URLs

The third SQL query you need to use is to update the post meta URLs. This query updates the URLs in the meta_value field in the wp_postmeta table.

UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://old-url.com/','http://new-url.com/');

It’s important to note that these SQL queries should only be used if you’re familiar with SQL and have a basic understanding of how WordPress works. If you’re not comfortable using SQL, it’s recommended to hire a professional to help you with the URL changes.

Conclusion

Updating the URLs in your WordPress database is essential when changing the URL structure of your website. Using SQL queries can help you update the URLs quickly and efficiently. However, it’s important to backup your website and be cautious when making changes to your WordPress database. Follow the steps outlined above to update the URLs in your WordPress database.