WordPress Update URLS

Last updated 3 months ago

PHP
/* Replaces URL in WordPress Home and Site URL in wp_options */
UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldsite.com', 'http://www.newsite.com') WHERE option_name = 'home' OR option_name = 'siteurl';

/* Replaces URL in GUID of all posts/cpt/etc */
/* https://deliciousbrains.com/wordpress-post-guids-sometimes-update/ */
UPDATE wp_posts SET guid = replace(guid, 'http://www.oldsite.com','http://www.newsite.com');

/* Replaces URL within all posts/cpt/etc content */
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldsite.com', 'http://www.newsite.com');

/* Replaces URL within all posts/cpt/etc metadata */
UPDATE wp_postmeta SET meta_value = replace(meta_value, 'http://www.oldsite.com', 'http://www.newsite.com');


/* Replaces URL in WordPress Links */
UPDATE wp_links SET link_url = replace(link_url, 'http://www.oldsite.com', 'http://www.newsite.com');

/* Replaces URL in WordPress Image Links */
UPDATE wp_links SET link_image = replace(link_image, 'http://www.oldsite.com', 'http://www.newsite.com');

/* Replaces URL in WordPress Users Website URL */
UPDATE wp_usermeta SET meta_value = replace(meta_value, 'http://www.oldsite.com', 'http://www.newsite.com');

/* Replaces URL in WordPress Comment Authors */
UPDATE wp_comments SET comment_author_url = REPLACE(comment_author_url, 'http://www.oldsite.com', 'http://www.newsite.com');

All code snippets are licensed GPLv2 or later unless otherwise stated.