Created
July 26, 2013 20:06
-
-
Save doitlikejustin/6091841 to your computer and use it in GitHub Desktop.
WordPress SQL replace old URL with new URL
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 @prefix = "wp_"; | |
SET @old = "http://www.old.com"; | |
SET @new = "http://www.new.com"; | |
SET @sql1 = CONCAT('UPDATE ', @prefix, 'options SET option_value = REPLACE(option_value,?,?)'); | |
SET @sql2 = CONCAT('UPDATE ', @prefix, 'posts SET guid = REPLACE(guid,?,?)'); | |
SET @sql3 = CONCAT('UPDATE ', @prefix, 'posts SET post_content = REPLACE(post_content,?,?)'); | |
PREPARE update1 FROM @sql1; | |
PREPARE update2 FROM @sql2; | |
PREPARE update3 FROM @sql3; | |
EXECUTE update1 USING @old, @new; | |
EXECUTE update2 USING @old, @new; | |
EXECUTE update3 USING @old, @new; | |
DEALLOCATE PREPARE update1; | |
DEALLOCATE PREPARE update2; | |
DEALLOCATE PREPARE update3; |
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 = "http://www.old.com"; | |
SET @new = "http://www.new.com"; | |
UPDATE wp_options | |
SET option_value = replace(option_value, @old, @new) | |
WHERE option_name = 'home' OR option_name = 'siteurl'; | |
UPDATE wp_posts | |
SET guid = replace(guid, @old, @new); | |
UPDATE wp_posts | |
SET post_content = replace(post_content, @old, @new); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, man!
This is one useful piece of SQL :)