Skip to content

Instantly share code, notes, and snippets.

@bahiirwa
Forked from jpederson/wp-update-url.sql
Created October 11, 2016 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bahiirwa/b44b87ad9ec08c409525d910310173b6 to your computer and use it in GitHub Desktop.
Save bahiirwa/b44b87ad9ec08c409525d910310173b6 to your computer and use it in GitHub Desktop.
This sql file will update the URLs in all relevant WordPress tables when you move a site form one domain to another. Simply change the variables at the top to your URLs and execute it.
SET @wp_url_old = 'http://oldurl.com', @wp_url_new = 'http://newurl.com';
UPDATE wp_options SET option_value = replace( option_value, @wp_url_old, @wp_url_new )
WHERE option_value LIKE CONCAT( '%', @wp_url_old, '%' );
UPDATE wp_posts SET guid = replace( guid, @wp_url_old, @wp_url_new );
UPDATE wp_posts SET post_content = replace( post_content, @wp_url_old, @wp_url_new );
UPDATE wp_postmeta SET meta_value = replace( meta_value, @wp_url_old, @wp_url_new );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment