Back to my Blog

Updating URL’s in the database after WordPress migration

I’m putting this here as it’s a code snippet I use all the time and if anything, it makes it easier for me to find.

Once you’ve migrated a WordPress site from one hosting to another (or set up a site locally) you will likely want to update all the URL’s throughout your website so they point to the correct place.

(I use phpmyadmin so I will talk about it in that context.)

Once you’ve imported your database into phpmyadmin, you’ll want to navigate to the SQL tab (see image below)

SQL tab within phpmyadmin

Then you’ll want to paste in the following code:

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,'','');

You’ll need to replace the and with your own URLs (don’t include trailing slashes).

Then press ‘Go’ and it should let you know how many rows it has replaced the URL in.

Leave a Reply

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