WordPress SQL queries to change the site URL

Changing a WordPress site domain is a common practice for developers, as you normally don’t work using what will be the final website’s URL. While I believe Backupbuddy’s plugin tools to export and import a website are by far the easiest way to move a website to a new URL, it can also be done directly on the database with this four SQL queries that:

  • Change Siteurl & Homeurl
  • Change GUID
  • Change URL in Content
  • Update Post Meta
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldsiteurl.com', 'http://www.newsiteurl.com') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET guid = REPLACE (guid, 'http://www.oldsiteurl.com', 'http://www.newsiteurl.com');

UPDATE wp_posts SET post_content = REPLACE (post_content, 'http://www.oldsiteurl.com', 'http://www.newsiteurl.com');

UPDATE wp_postmeta SET meta_value = REPLACE (meta_value, 'http://www.oldsiteurl.com','http://www.newsiteurl.com');

For more details on how this works, and a few more SQL queries for WordPress, I recommend this article on onextrapixel.com.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s