Skip to content

Instantly share code, notes, and snippets.

@chriskempson
Last active October 12, 2015 20:58
Show Gist options
  • Save chriskempson/4086580 to your computer and use it in GitHub Desktop.
Save chriskempson/4086580 to your computer and use it in GitHub Desktop.
Wordpress Replace URL's SQL
SET @old_url = 'old';
SET @new_url = 'new';
UPDATE wp_posts
SET post_content = REPLACE(post_content, @old_url, @new_url),
post_excerpt = REPLACE(post_excerpt, @old_url, @new_url),
guid = REPLACE(guid, @old_url, @new_url);
UPDATE wp_options
SET option_value = REPLACE(option_value, @old_url, @new_url)
WHERE option_value NOT LIKE 'a:%;}';
UPDATE wp_options SET option_value = REPLACE(
option_value,
CONCAT('s:', LENGTH(@old_url), ':"', @old_url, '"'),
CONCAT('s:', LENGTH(@new_url), ':"', @new_url, '"')
);
UPDATE wp_postmeta
SET meta_value = REPLACE(meta_value, @old_url, @new_url)
WHERE meta_value NOT LIKE 'a:%;}';
UPDATE wp_postmeta SET meta_value = REPLACE(
meta_value,
CONCAT('s:', LENGTH(@old_url), ':"', @old_url, '"'),
CONCAT('s:', LENGTH(@new_url), ':"', @new_url, '"')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment