Update Site URL in WordPress

Update Site URL in WordPress

If you need to move your WordPress blog to a new URL you will need to update the database, use these simple queries to do the work for you. Just replace the relevant old and new URLs, and if you use a table prefix other than wp_ then change that.

/* update all post permalinks */
update wp_posts
set guid = REPLACE(guid, 'http://www.oldsite.com', 'http://www.newsite.com')
where guid LIKE '%http://www.oldsite.com%';
/* update all post content */
update wp_posts
SET post_content = REPLACE(post_content, 'http://www.oldsite.com', 'http://www.newsite.com')
where post_content LIKE '%http://www.oldsite.com%';
/* update all post meta */
update wp_postmeta
SET meta_value = REPLACE(meta_value, 'http://www.oldsite.com', 'http://www.newsite.com')
where meta_value LIKE '%http://www.oldsite.com%';
/* update all options */
update wp_options
set option_value = REPLACE(option_value, 'http://www.oldsite.com', 'http://www.newsite.com')
where option_value LIKE '%http://www.oldsite.com%';