Last active
March 13, 2018 19:23
-
-
Save bhubbard/9102686 to your computer and use it in GitHub Desktop.
These are various SQL Queries to run to update urls within a WordPress Database. These queries assume the table prefix is the standard `wp_`, if you have a custom prefix you will need to update the queries. I also recommend changing the default urls using this method: https://codex.wordpress.org/Changing_The_Site_URL or http://codex.wordpress.or…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Set our Old and New URLS */ | |
SET @oldurl := "http://www.oldsite.com"; | |
SET @newurl := "http://www.newsite.com"; | |
/* Replaces URL in WordPress Home and Site URL in wp_options */ | |
UPDATE wp_options SET option_value = replace(option_value, @oldurl, @newurl) 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, @oldurl, @newurl); | |
/* Replaces URL within all posts/cpt/etc content */ | |
UPDATE wp_posts SET post_content = replace(post_content, @oldurl, @newurl); | |
/* Replaces URL within all posts/cpt/etc metadata */ | |
UPDATE wp_postmeta SET meta_value = replace(meta_value, @oldurl, @newurl); | |
/* Replaces URL in WordPress Links */ | |
UPDATE wp_links SET link_url = replace(link_url, @oldurl, @newurl); | |
/* Replaces URL in WordPress Image Links */ | |
UPDATE wp_links SET link_image = replace(link_image, @oldurl, @newurl); | |
/* Replaces URL in WordPress Users Website URL */ | |
UPDATE wp_usermeta SET meta_value = replace(meta_value, @oldurl, @newurl); | |
/* Replaces URL in WordPress Comment Authors */ | |
UPDATE wp_comments SET comment_author_url = REPLACE(comment_author_url, @oldurl, @newurl); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/messified/7e6b3ef80f84c7a2eb8d
http://www.onextrapixel.com/2010/01/30/13-useful-wordpress-sql-queries-you-wish-you-knew-earlier/
https://gist.github.com/davejamesmiller/a8733a3fbb17e0ff0fb5
https://gist.github.com/Vunb/9087113