Skip to content

Instantly share code, notes, and snippets.

@retlehs
Last active January 26, 2022 03:48
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 9 You must be signed in to fork a gist
  • Save retlehs/aa47003249623e52b95a3fcd6f69b8fb to your computer and use it in GitHub Desktop.
Save retlehs/aa47003249623e52b95a3fcd6f69b8fb to your computer and use it in GitHub Desktop.
WP-CLI aliases sync example
read -r -p "Would you really like to reset your development database and pull the latest from production? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
wp @development db reset --yes &&
wp @production db export - > sql-dump-production.sql &&
wp @development db import sql-dump-production.sql &&
wp @development search-replace https://example.com https://example.dev
fi
path: web/wp
@production:
ssh: web@example.com/srv/www/example.com/current
@development:
ssh: vagrant@example.dev/srv/www/example.com/current
@ttcremers
Copy link

I've always been a bit fuzzy on this, why use the search-replace on the sites url when it's much easier to just set WP_HOME and WP_SITEURL in the wp config

@taylorgorman
Copy link

I would guess because the WordPress editor inserts the site URL when adding internal links and img tags. So you have to change those strings in the post_content field for every post.

Those URLs also exist in the wp_options table, which is from where all the WordPress core functions get them (I'm mostly sure). You could use the wp-config constants in your own themes and plugins, but other plugin devs will still use them. ..Although I suppose you could hook into those functions and switch them to pull from the constants. But you'd still have the post_content problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment