Skip to content

Instantly share code, notes, and snippets.

@ethanpil
Last active February 21, 2022 21:43
Show Gist options
  • Save ethanpil/94195cc149f9e00504972dbb18994ac8 to your computer and use it in GitHub Desktop.
Save ethanpil/94195cc149f9e00504972dbb18994ac8 to your computer and use it in GitHub Desktop.
Use WP CLI to migrate a WordPress database with search-replace
#On the source WP site:
wp db export wp-export.sql --all-tables
#On the destination site
#First import the new DB
wp db import wp-export.sql
## Replace basic URLs
wp search-replace oldsite.com newsite.com --skip-columns=guid --all-tables
## Replace URL escaped strings
wp search-replace "https:\/\/oldsite.com\/" "https:\/\/newsite.com\/" --skip-columns=guid --all-tables
## Replace URL encoded strings
wp search-replace 'http%3A%2F%2Foldsite.com' 'http%3A%2F%2Fnewsite.com' --skip-columns=guid --all-tables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment