Last active
April 21, 2016 07:12
-
-
Save artifex404/d39cb18d1f0e494daeb337ad21e1aa9e to your computer and use it in GitHub Desktop.
This query will find and replace URLs in all standard WordPress installation SQL tables. Remember to save the permalinks from the administration panel after doing this query.
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 @olddomain = "'olddomain.dev'"; | |
SET @newdomain = "'newdomain.com'"; | |
SET @prefix = "wp_"; | |
SET @postmeta = CONCAT('UPDATE ', @prefix, 'postmeta SET meta_value = REPLACE(meta_value,', @olddomain, ',',@newdomain,')'); | |
SET @excerpt = CONCAT('UPDATE ', @prefix, 'posts SET post_excerpt = REPLACE(post_excerpt,', @olddomain, ',',@newdomain,')'); | |
SET @content = CONCAT('UPDATE ', @prefix, 'posts SET post_content = REPLACE(post_content,', @olddomain, ',',@newdomain,')'); | |
SET @guid = CONCAT('UPDATE ', @prefix, 'posts SET guid = REPLACE(guid,', @olddomain, ',',@newdomain,')'); | |
SET @options = CONCAT('UPDATE ', @prefix, 'options SET option_value = REPLACE(option_value,', @olddomain, ',',@newdomain,') WHERE option_name = "siteurl" OR option_name = "home"'); | |
PREPARE QUERY FROM @postmeta; EXECUTE QUERY; | |
PREPARE QUERY FROM @excerpt; EXECUTE QUERY; | |
PREPARE QUERY FROM @content; EXECUTE QUERY; | |
PREPARE QUERY FROM @guid; EXECUTE QUERY; | |
PREPARE QUERY FROM @options; EXECUTE QUERY; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment