I spent some time this evening updating the link structure for the blog and testing some tweaks to the site. Being an IT guy, I used a testing environment for, well, testing things out before implementing them here. In the process of refreshing the database in the testing environment, I had to deal with an issue that WordPress has: the site’s base URL is stored in the database, and each post has an absolute URL stored in the database too. Really, WordPress should have been designed to use relative URLs, but since it’s not, a little extra tweaking is necessary.
So, copying a WordPress database to use on another WordPress installation serving a different URL means all of those addresses need to be updated in the new database copy.
Some SQL to do just that:
UPDATE wp_options SET option_value = replace(option_value, 'http://old-domain.com', 'http://new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://old-domain.com','http://new-domain.com');
UPDATE wp_posts SET post_content = replace(post_content, 'http://old-domain.com', 'http://new-domain.com');
If you have an additional part to your URL, such as “/blog”, the replace command will not overwrite it and it will work fine.
#
Great posting! http://codex.wordpress.org/Changing_The_Site_URL is a good resource, but it’s not clear about the post_content column and isn’t well written which makes it confusing.
Also, I did a:
UPDATE wp_postmeta SET meta_value = replace(meta_value, ‘http://old-domain.com’, ‘http://new-domain.com’);
==>Lancer—