WordPress Url Change Database SQL Query

First I query the current website url in the db…

SELECT *  FROM wp_options  WHERE option_name = 'home' OR option_name = 'siteurl';

Then I replace the current.website.url with the value from the previous query and replace new.website.url with the new url value in the query below (exclude the http prefixes)…

UPDATE wp_posts SET guid = replace(guid, 'current.website.url','new.website.url');
UPDATE wp_posts SET post_content = replace(post_content, 'current.website.url','new.website.url');
UPDATE wp_postmeta SET meta_value = replace(meta_value, 'current.website.url','new.website.url');
UPDATE wp_options SET option_value = replace(option_value, 'current.website.url','new.website.url') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_usermeta SET meta_value = replace(meta_value, 'current.website.url','new.website.url');

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>