Skip to content

Instantly share code, notes, and snippets.

@jpederson
Last active November 9, 2020 20:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jpederson/2f526432fa1ba531b4bf to your computer and use it in GitHub Desktop.
Save jpederson/2f526432fa1ba531b4bf to your computer and use it in GitHub Desktop.
This sql file will update the URLs in all relevant WordPress tables when you move a site form one domain to another. Simply change the variables at the top to your URLs and execute it.
SET @wp_url_old = 'http://oldurl.com', @wp_url_new = 'http://newurl.com';
UPDATE wp_options SET option_value = replace( option_value, @wp_url_old, @wp_url_new )
WHERE option_value LIKE CONCAT( '%', @wp_url_old, '%' );
UPDATE wp_posts SET guid = replace( guid, @wp_url_old, @wp_url_new );
UPDATE wp_posts SET post_content = replace( post_content, @wp_url_old, @wp_url_new );
-- if you have plugins that include serialized arrays of data in custom fields (such as some
-- implementations of cmb/cmb2), you may want to comment this query out, otherwise, it's
-- usually safe.
UPDATE wp_postmeta SET meta_value = replace( meta_value, @wp_url_old, @wp_url_new );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment