Skip to content

Instantly share code, notes, and snippets.

@artifex404
Last active April 21, 2016 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save artifex404/d39cb18d1f0e494daeb337ad21e1aa9e to your computer and use it in GitHub Desktop.
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.
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