Skip to content

Instantly share code, notes, and snippets.

@morehawes
Created January 12, 2024 20:54
Show Gist options
  • Save morehawes/4c7736d0a2164adf6367a7484c22c146 to your computer and use it in GitHub Desktop.
Save morehawes/4c7736d0a2164adf6367a7484c22c146 to your computer and use it in GitHub Desktop.
Change the URL of a WordPress Site
/*
Useful when moving a WordPress Install
💥💥💥💥 ALWAYS BACK-UP YOUR DATABASE!!! 💥💥💥💥
Use at your own risk. It may not take into account all
modifications added by other themes/plugins etc.
It performs a find/replace on the following tables:
Options Table (wp_options - home/site URL only)
Posts Table (wp_posts - guid/post_content columns)
Post Meta Table (wp_postmeta - meta_value column)
Update Your ___PREFIX___ , ___FROM___ and __TO__ :
--------------------------------------------------------------
UPDATE ___PREFIX___options
SET option_value = replace(option_value, '___FROM___', '___TO___')
WHERE option_name = 'home'
OR option_name = 'siteurl';
UPDATE ___PREFIX___posts
SET guid = replace(guid, '___FROM___','___TO___');
UPDATE ___PREFIX___posts SET post_content = replace(post_content, '___FROM___', '___TO___');
UPDATE ___PREFIX___postmeta SET meta_value = replace(meta_value,'___FROM___','___TO___');
--------------------------------------------------------------
Example:
*/
UPDATE bhy_options
SET option_value = replace(option_value, 'http://joe-dev.local/bighikesyosemite', 'https://www.ogis.app/YNP')
WHERE option_name = 'home'
OR option_name = 'siteurl';
UPDATE bhy_posts
SET guid = replace(guid, 'http://joe-dev.local/bighikesyosemite','https://www.ogis.app/YNP');
UPDATE bhy_posts SET post_content = replace(post_content, 'http://joe-dev.local/bighikesyosemite', 'https://www.ogis.app/YNP');
UPDATE bhy_postmeta SET meta_value = replace(meta_value,'http://joe-dev.local/bighikesyosemite','https://www.ogis.app/YNP');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment