This is helpful for transferring to a new domain / publishing your site after working locally. It is not the best method to use with wordpress as it can casue problems with some widgets which means they dissapear. But sometimes, needs must...
WordPress stores many options as "serialized data", which contains both the string content of things and their length. So when you modify the URL and the length changes, then the serialized data is no longer correct, and PHP rejects it. More info
The main tables you will need to update for any Wordpress installation are wp_options
, wp_posts
and wp_post_meta
. The SQL below will find any instance of your old domain and replace it with your new domain. Making sure your site works properly and loads all attachments on the new server/domain.
Don't use this method unless you are already familier with using phpMyAdmin.
UPDATE wp_options SET option_value = replace(option_value, 'http://www.olddomain.co.uk', 'http://www.newdomain.co.uk');
UPDATE wp_posts SET guid = replace(guid, 'http://www.olddomain.co.uk', 'http://www.newdomain.co.uk');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.olddomain.co.uk', 'http://www.newdomain.co.uk');
UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://www.olddomain.co.uk', 'http://www.newdomain.co.uk');
When I do this I like to handle a couple of other jobs as well...
The following line will set the blog to public so it can get indexed on Google. Switch the boolean values round when setting up a demo site to make sure Google does not index the demo.
UPDATE wp_options SET option_value = replace(option_value, '0', '1') WHERE option_name = 'blog_public';
Some plugins you use may create other tables that use your domain. One example I often use is Redirection. Here's how to update this table too:
UPDATE wp_redirection_logs SET referrer = replace(referrer, 'http://www.olddomain.co.uk', 'http://www.newdomain.co.uk');
Written with StackEdit.