👈 back home

WordPress SQL Query: Move old domain to new domain

Published 2014-03-09

When you move your development wordpress project from localhost or old domain to live server or new domain, you can use this handy query.

Change Author on all posts at once

If you would to change all posts from spesific username to another user, use this SQL Query:

SELECT ID, display_name FROM wp_users;
UPDATE wp_posts SET post_author=NEW_AUTHOR_ID WHERE post_author=OLD_AUTHOR_ID;

Update URL Site

Update your old domain to new one. It’s helpful when you move your file from development (localhost) to production (live server).

UPDATE wp_options SET option_value = replace(option_value, 'http://www.old-domain.com', 'http://www.new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET guid = replace(guid, 'http://www.old-domain.com','http://www.new-domain.com');

UPDATE wp_posts SET post_content = replace(post_content, 'http://www.old-domain.com', 'http://www.new-domain.com');

Update URL path in post content

Post article sometimes containing full path address, we can fix it using this query:

UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'http://www.old-domain.com', 'http://www.new-domain.com');