Skip to content

Instantly share code, notes, and snippets.

@FernE97
Last active January 6, 2016 23:17
Show Gist options
  • Save FernE97/8139535 to your computer and use it in GitHub Desktop.
Save FernE97/8139535 to your computer and use it in GitHub Desktop.
Useful for changing over WordPress urls
-- Avoid updating serialized strings with "NOT LIKE '%{%'"
UPDATE wp_options SET option_value = REPLACE(option_value, '//olddomain.com', '//newdomain.com') WHERE option_value NOT LIKE '%{%';
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, '//olddomain.com', '//newdomain.com') WHERE meta_value NOT LIKE '%{%';
UPDATE wp_posts SET post_content = REPLACE(post_content, '//olddomain.com', '//newdomain.com') WHERE post_content NOT LIKE '%{%';
UPDATE wp_posts SET guid = REPLACE(guid, '//olddomain.com', '//newdomain.com') WHERE post_type = 'attachment';
-- File paths
UPDATE wp_options SET option_value = REPLACE(option_value, '/home/old/path', '/home/new/path') WHERE option_value NOT LIKE '%{%';
UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, '/home/old/path', '/home/new/path') WHERE meta_value NOT LIKE '%{%';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment