Last active
November 9, 2020 20:53
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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