Created
January 27, 2013 23:00
-
-
Save wesleytodd/4651124 to your computer and use it in GitHub Desktop.
Change the url of a WordPress site.
This file contains hidden or 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 = "http://oldside.com"; | |
SET @new_url = "http://newsite.com"; | |
SET @prefix = "wp_"; | |
SET @s1 = CONCAT("UPDATE ", @prefix, "options SET option_value = replace(option_value, '", @old_url, "', '", @new_url, "') WHERE option_name = 'home' OR option_name = 'siteurl';"); | |
PREPARE s1 FROM @s1; | |
EXECUTE s1; | |
SET @s2 = CONCAT("UPDATE ", @prefix, "posts SET guid = replace(guid, '", @old_url, "', '", @new_url, "');"); | |
PREPARE s2 FROM @s2; | |
EXECUTE s2; | |
SET @s3 = CONCAT("UPDATE ", @prefix, "posts SET post_content = replace(post_content, '", @old_url, "', '", @new_url, "');"); | |
PREPARE s3 FROM @s3; | |
EXECUTE s3; | |
SET @s4 = CONCAT("UPDATE ", @prefix, "postmeta SET meta_value = replace(meta_value, '", @old_url, "', '", @new_url, "');"); | |
PREPARE s4 FROM @s4; | |
EXECUTE s4; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The problem with the method are serialized options, which have the string length defined in them. So if old_url and new_url differ in length, you might destroy your serialized data.
For this I'm using http://interconnectit.com/products/search-and-replace-for-wordpress-databases/ instead