Don’t hesitate to contact us if you have any feedback.

WordPress – Updating site URL directly in the Database

Introduction

When moving a WordPress website to a new domain, it’s crucial to update the site’s URL to ensure that all references point to the correct location. This can be accomplished directly in the database using a series of SQL statements.

SQL Update Statements

The following SQL commands are designed to update various parts of the WordPress database, where the old URL is referenced:

-- Update site URL and home URL
UPDATE wp_options SET option_value = replace(option_value, 'http://oldurl.com', 'http://newurl.com') 
WHERE option_name = 'home' OR option_name = 'siteurl';

-- Update URLs in post GUIDs
UPDATE wp_posts SET guid = replace(guid, 'http://oldurl.com','http://newurl.com');

-- Update URLs in post content
UPDATE wp_posts SET post_content = replace(post_content, 'http://oldurl.com', 'http://newurl.com'); 

-- Update URLs in post meta
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://oldurl.com','http://newurl.com');

Attention Required

⚠️ Important Precautions ⚠️
Before executing these commands, it’s imperative to:

  • Verify Table Prefix: Ensure that the table prefix (wp_ by default) matches the prefix used in your WordPress installation.
  • Backup Database: Always create a backup of your database before running any update queries.
  • Confirm URLs: Double-check the old and new URLs to ensure they are correct.

Conclusion

Executing these SQL statements will comprehensively update your WordPress website’s URLs within the database. It’s a direct and efficient method to assist in migrating your site to a new domain. However, due to the sensitivity of database operations, it should be approached with caution and always with a fresh backup at hand.


Comments

Leave a Reply

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