Last active
October 12, 2015 20:58
-
-
Save chriskempson/4086580 to your computer and use it in GitHub Desktop.
Wordpress Replace URL's SQL
This file contains 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 @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