Skip to content

Instantly share code, notes, and snippets.

@geoffyuen
Last active February 16, 2023 06:07
Show Gist options
  • Save geoffyuen/08fa8dee1b8e6d5ae7d9104558ad5c3b to your computer and use it in GitHub Desktop.
Save geoffyuen/08fa8dee1b8e6d5ae7d9104558ad5c3b to your computer and use it in GitHub Desktop.
WP CLI Cheatsheet

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:

  1. Install wp cli: brew install wp-cli mysql if you don't already have these on your system
  2. 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*
  3. In Local, under the Database tab enter the Remote Host ip and Remove Port when prompted by the script
  4. 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

Export from staging, search and replace, import to prod

https://www.reddit.com/r/Wordpress/comments/bxftxk/how_are_people_managing_wordpress_release/eq6kjz6/?st=k0s6kcqj&sh=e21fea0f

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