We need to move a WordPress 2.7 install from a development domain to the live environment via straight FTP transfer and phpMyAdmin dump. We bypass the Export / Import functions in WordPress admin so that we can preserve our myriad plugin settings when making the domain switch. But now our links are all pointing at the old URL and the upload path is all wonky. WTF? Fear not, you can fix all those problems by running this tasty little SQL script on your WordPress database via phpMyAdmin (don’t forget to replace the values with the appropriate values for your environment):
## — replace absolute URLs that point to the old domain
UPDATE wp_posts
UPDATE wp_posts
SET guid = REPLACE ( guid, ‘www.oldsite.com’, ‘www.newsite.com’ )
WHERE guid LIKE ‘%www.oldsite.com%’
;
WHERE guid LIKE ‘%www.oldsite.com%’
;
UPDATE wp_posts
SET post_content = REPLACE ( post_content, ‘www.oldsite.com’, ‘www.newsite.com’ )
WHERE post_content LIKE ‘%www.oldsite.com%’
;
WHERE post_content LIKE ‘%www.oldsite.com%’
;
UPDATE wp_options
SET option_value = REPLACE ( option_value, ‘www.oldsite.com’, ‘www.newsite.com’ )
WHERE option_value LIKE ‘%www.oldsite.com%’
;
WHERE option_value LIKE ‘%www.oldsite.com%’
;
## — replace absolute server paths
UPDATE wp_options
SET option_value = REPLACE ( option_value, ‘/old/server/path/’, ‘/new/server/path/’ )
WHERE option_value LIKE ‘%/old/server/path/%’
;
WHERE option_value LIKE ‘%/old/server/path/%’
;
UPDATE wp_postmeta
SET meta_value = REPLACE ( meta_value, ‘/old/server/path/’, ‘/new/server/path/’ )
WHERE meta_value LIKE ‘%/old/server/path/%’
;
WHERE meta_value LIKE ‘%/old/server/path/%’
;