Posted Sunday, September 17, 2023
WP CLI Cheatsheet
manage WordPress from the commandline
WP CLI cheatsheet
You may need to be at the root of your WP install. In Local by Flywheel this will be the app directory.
Backup database
wp db export your/path/here/my_wordpress_db.sql
Import database
wp db import your/path/here/my_wordpress_db.sql
Ye' ol' database url search and replace (handles serialization)
wp search-replace 'http://oldurl.com' 'http://newurl.com'
Add --dry-run
to test.
You may need to change the siteurl and home url as well.
Change siteurl and home
wp option update home 'http://new.url'
wp option update siteurl 'http://new.url'
Search for a plugin
wp plugin search "yoast acf"
Install and activate plugin
wp plugin install --activate plug-in-slug
Install plugins from a text file
wp plugin install --activate $(<plugin-slugs.txt)
Install plugins all in one line
wp plugin install --activate stop-emails modify-comment-parent simple-google-analytics-tracking
Update all plugins
wp plugin update --all
Overwrite local changes from remote
git fetch --all
git reset --hard origin/master
or
git reset --hard origin/<branch_name>
Install WP CLI directly on machine (not using Local Flywheel)
brew install wp-cli
Use WP CLI on a Local Flywheel site from commandline
If you want to make a export/import a database backup quickly with the commandline and don't want to go to the Local app, right-click your site to ssh in:
- Install wp cli:
brew install wp-cli mysql
if you don't already have these on your system - In your
~/Local Sites/{{ sitefolder }}
folder (app, conf, logs folders are here too):curl -O https://raw.githubusercontent.com/salcode/ssh-into-local-by-flywheel/master/wpcli-lbf-setup && bash wpcli-lbf-setup && rm -rf ./wpcli-lbf-setup
* - In Local, under the Database tab enter the Remote Host ip and Remove Port when prompted by the script
- Your folder should now contain: app, conf, logs, wp-cli.local.php, wp-cli.local.yml
Test to see if it works but opening up a terminal somewhere in your site folder and trying a cli command. Eg. wp option get siteurl
should show your site url. Now you can make backups simply, even from the VSCode terminal: wp db export your/path/here/my_wordpress_db.sql
. Combine this with git lfs
and you can keep your database in your git repo.
https://salferrarello.com/wp-cli-local-by-flywheel-without-ssh/
*I wonder if this could be shortened to curl -s https://raw.githubusercontent.com/salcode/ssh-into-local-by-flywheel/master/wpcli-lbf-setup | bash
Run remotely
wp [email protected]/var/www/html/ plugin list