WP-CLI Commands Cheat Sheet for WordPress

A WP-CLI commands cheat sheet grouped by task: installing WordPress and wp-config.php, updates, users, database export and import, search-replace, cache, cron, media and the errors that stop them.

Repeating the same WordPress job in wp-admin gets slow once it spans dozens of plugins, users or sites. WP-CLI runs that work from the terminal, but one wrong flag or folder can rewrite a live database in seconds.

This WP-CLI commands cheat sheet groups the commands by the job in front of you, from installing WordPress to clearing cache and running cron. Our advice is to learn the read-only commands first and to export the database before any command that writes.

WP-CLI Commands at a Glance

These are the commands most WordPress jobs start with. The last column matters most, because a command that changes the site deserves a backup first.

TaskCommandChanges the site?
Check WP-CLI and PHPwp --infoNo
Confirm which site you're onwp option get homeNo
Download WordPresswp core downloadAdds core files
Create wp-config.phpwp config createAdds a file
List pending plugin updateswp plugin list --update=availableNo
Update every pluginwp plugin update --allYes
Back up the databasewp db export backup.sqlWrites a file only
Restore a databasewp db import backup.sqlYes, overwrites tables
Preview a URL changewp search-replace OLD NEW --dry-runNo
Reset a passwordwp user reset-passwordYes
Empty the object cachewp cache flushYes, temporarily
Run due cron eventswp cron event run --due-nowYes
Rebuild missing thumbnailswp media regenerate --only-missingAdds image files

wp help followed by a command name prints every option for that command, and the official WP-CLI command reference covers the same ground online. Some options in that reference only exist in the nightly build, such as --with-dependencies for wp plugin install, so everything on this page sticks to the stable release.

Install WP-CLI

WP-CLI needs PHP 7.2.24 or later and nothing beyond what WordPress itself needs. Many managed hosts already include it, so wp --info is worth running before you install anything.

On your own server, the official installation guide uses the Phar file, a single PHP archive:

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
php wp-cli.phar --info
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp
wp --info

wp --info reports the PHP binary, the php.ini file and the WP-CLI version, so a PHP mismatch shows up before it breaks a command. wp cli version prints the installed release and wp cli update replaces a Phar install with the latest one.

Two other setups come up often:

  • No sudo on shared hosting: the Phar can stay in your home folder, with alias wp='php ~/bin/wp-cli.phar' added to ~/.bashrc.
  • macOS: brew install wp-cli installs it through Homebrew, which the handbook lists as a supported method.

Install WordPress and Create wp-config.php

A fresh install from the terminal takes 4 commands. They run from the empty folder that will become the site root, or from anywhere with --path pointing at it.

wp core download --locale=en_US
wp config create --dbname=example_db --dbuser=example_user --prompt=dbpass
wp db create
wp core install --url=https://example.com --title="Example Site" --admin_user=example_admin --admin_email=admin@example.com --prompt=admin_password

--prompt=dbpass and --prompt=admin_password ask for each password instead of taking it on the command line. That keeps both out of your shell history, which matters on any server other people can log in to.

  • wp config create checks that the user can connect to the database server before it writes the file. The database itself doesn't have to exist yet, and --skip-check turns the check off.
  • wp db create needs a database user that is allowed to create databases. On most shared hosts the database is created in the control panel instead, so this step gets skipped.
  • wp config set WP_DEBUG true --raw adds or changes any constant later. --raw writes a PHP boolean instead of the text 'true'.

This Does Not Seem to Be a WordPress Installation

WP-CLI looks for wp-includes/version.php in the current folder, or in the folder --path names. When that file isn't there, every command except wp core download stops with this error:

Error: This does not seem to be a WordPress installation.
The used path is: /home/example/
Pass --path=`path/to/wordpress` or run `wp core download`.

The usual causes are these:

  • wp config create before wp core download: the config command checks for core files first, so it fails in an empty folder. Downloading core first fixes it.
  • The wrong folder: the shell is in the home directory instead of public_html or the site root. A cd into the folder that holds wp-config.php, or --path, fixes it.
  • WordPress in a subfolder: some setups keep core in a folder such as /wp. --path or a path: line in wp-cli.yml points WP-CLI there.
  • A stale wp-cli.yml: WP-CLI reads that file from the current folder and every folder above it, so an old path: value can send it somewhere else.
cd /var/www/example.com/public_html
ls wp-includes/version.php
wp core version

wp core version --path=/var/www/example.com/public_html

2 related errors point at the next step. "It seems, the WordPress core files do not have the proper file permissions" means the files exist but your user can't read them, which our WordPress file permissions guide covers. "'wp-config.php' not found" means core is in place and wp config create is the missing step.

Update WordPress Core, Plugins and Themes

Updates are a common WP-CLI job, and a careless --all can break several plugins at once. This is the order we'd follow on a live site: check what's pending, back up, then update core before plugins and themes.

wp core check-update
wp plugin list --update=available
wp theme list --update=available
wp db export before-updates.sql
wp core update
wp core update-db
wp plugin update --all --dry-run
wp plugin update --all --exclude=woocommerce
wp theme update --all
wp language core update
  • wp core update --minor limits a core update to maintenance and security releases on the current branch.
  • wp plugin update takes --minor and --patch for the same restraint, plus --exclude for plugins that need a manual test first.
  • --dry-run lists the plugins that would update without changing anything.
  • WP-CLI switches maintenance mode on during wp plugin update --all and off when the updates finish.
  • wp core update-db runs the database upgrade a new core version can need, the step wp-admin normally prompts for.

For a site you look after every month, our WordPress maintenance guide covers what to check around these commands.

Check Core and Plugin Files for Changes

After an update or a suspected hack, wp core verify-checksums compares every core file with the checksums WordPress.org publishes. wp plugin verify-checksums --all does the same for plugins from the WordPress.org directory.

wp core verify-checksums
wp plugin verify-checksums --all

A clean result only covers those files. Malicious code in uploads, a premium plugin, the database or a cron event won't show up in either check.

Manage Plugins and Themes

Plugin and theme commands accept a WordPress.org slug, a local ZIP file or a ZIP URL. The slug is the folder name, such as akismet, rather than the display name.

wp plugin list --status=active
wp plugin install hello-dolly --activate
wp plugin install ../my-plugin.zip --activate
wp plugin activate akismet
wp plugin deactivate akismet
wp plugin status akismet
wp plugin delete hello-dolly
wp theme list
wp theme install twentytwentyfive --activate
wp theme activate twentytwentyfive
wp theme delete twentytwentythree
  • wp plugin delete removes the files without deactivating the plugin or running its uninstall routine. wp plugin deactivate --uninstall deactivates it and runs that cleanup.
  • wp theme delete refuses the active theme unless --force is added.
  • wp plugin install with --version fetches a specific release from WordPress.org, which helps when the latest one breaks something.

When a site breaks and a plugin is the likely cause, wp plugin deactivate --all rules plugins in or out in one step. It is wise to save the active list first, because wp plugin activate --all would also switch on plugins that were off before:

wp plugin list --status=active --field=name > active-plugins.txt
wp plugin deactivate --all
wp plugin activate $(cat active-plugins.txt)

Manage Users

User commands beat wp-admin when you need to audit administrators, lock someone out or fix an account you can't log in to.

wp user list --role=administrator --fields=ID,user_login,user_email,user_registered
wp user create jane jane@example.com --role=editor --send-email
wp user reset-password jane --skip-email --show-password
wp user set-role jane author
wp user session destroy jane --all
wp user delete 12 --reassign=1
  • wp user create prints a generated password when --user_pass is left out, and --send-email emails the new user.
  • wp user reset-password emails the user by default. --skip-email --show-password prints the new password in the terminal instead.
  • wp user session destroy --all logs a user out on every device, a sensible first step after a suspected account takeover.
  • wp user delete without --reassign deletes that user's posts along with the account. On multisite it only removes the user from the current site unless --network is added.

Export and Import the Database

wp db export and wp db import read the credentials from wp-config.php and call the MySQL tools for you. That makes them the quickest backup and restore on any server with shell access.

wp db export backup.sql
wp db export --tables=wp_posts,wp_postmeta posts.sql
wp db export --exclude_tables=wp_users,wp_usermeta no-accounts.sql
wp db export - | gzip > backup.sql.gz
wp db import backup.sql
gunzip < backup.sql.gz | wp db import -
  • wp db import overwrites any table with the same name. It doesn't create the database, so wp db create comes first on an empty server.
  • Table names follow the site's prefix. wp db prefix prints it, since plenty of sites don't use wp_.
  • The - sends the export to standard output and lets the import read from it, which keeps the gzip step in one line.
  • An export holds every password hash and email address on the site. It belongs outside the web root, never in a folder a browser can reach.

Moving a whole site also means moving the files, which our WordPress migration tutorial walks through. A manual export protects only the moment you ran it, so scheduled copies still come from the host or one of the WordPress backup plugins we compared.

Check and Maintain the Database

wp db check
wp db size --tables --human-readable
wp db optimize
wp db repair
wp db query "SELECT COUNT(*) FROM wp_posts WHERE post_status = 'trash'"
wp db reset --yes

wp db size --tables is a good first look when the admin feels slow, because one oversized log or options table stands out quickly. wp db reset --yes drops every table without asking, so it belongs on local and staging copies only.

Teams that share a server often block it outright with a disabled_commands list in wp-cli.yml. That is a cheap guard against a reset typed into the wrong terminal.

Search and Replace URLs

wp search-replace swaps one string for another across the database and handles serialized PHP data, which a plain SQL UPDATE corrupts. It is the standard step after a domain change or a move from HTTP to HTTPS.

wp search-replace 'https://staging.example.com' 'https://example.com' --dry-run
wp search-replace 'https://staging.example.com' 'https://example.com' --skip-columns=guid
wp search-replace 'http://example.com' 'https://example.com' --all-tables-with-prefix --precise
wp search-replace 'https://old.example' 'https://new.example' --export=migrated.sql

Our advice is to read the dry-run counts before the real run and to leave the guid column alone on a live site. The full workflow, with multisite and regex cases, lives in our WP-CLI search-replace guide.

Clear Cache, Transients and Rewrite Rules

These commands clear stored data that WordPress and its plugins rebuild on demand. The cost is a few slower page loads while that data fills back in.

wp cache type
wp cache flush
wp cache flush-group my_group
wp transient list
wp transient delete --expired
wp transient delete --all
wp rewrite flush
wp rewrite flush --hard
  • wp cache type names the object cache in use. "Default" means no persistent cache, so a flush only clears memory for that one command.
  • wp cache flush empties the object cache, such as Redis or Memcached. It doesn't purge a page cache plugin or a CDN, which have their own commands or dashboards.
  • wp cache flush-group needs WP-CLI 2.8 or later and an object cache that supports group flushing.
  • wp transient delete --expired is routine housekeeping. --all removes every transient, so plugins rebuild them on the next requests.
  • wp rewrite flush fixes 404 errors after a permalink or custom post type change. --hard also rewrites the Apache rules file (.htaccess) and works on single sites only.

Page caching is a separate layer, and our WordPress caching plugins comparison covers how each one clears it.

Run and Debug WP-Cron

WP-Cron runs scheduled jobs when someone loads a page, so on a quiet site backups, emails and scheduled posts can fire late. These commands show what is queued and run it on demand.

wp cron event list
wp cron event list --fields=hook,next_run_relative,recurrence
wp cron event run --due-now
wp cron event run wp_version_check
wp cron event delete my_old_hook
wp cron schedule list
wp cron test

For time-sensitive jobs, it is wise to move WP-Cron to a real server cron. The switch takes 2 parts: a constant that stops the page-load trigger and a crontab line that runs due events every 5 minutes.

wp config set DISABLE_WP_CRON true --raw
*/5 * * * * /usr/local/bin/wp --path=/var/www/example.com cron event run --due-now --quiet

Cron runs with a short PATH, so the full path to wp matters. After the change, wp cron test reports an error because DISABLE_WP_CRON is set, which is expected.

Manage Media

Media commands rebuild thumbnails after a theme changes its image sizes and import files without the upload screen.

wp media image-size
wp media regenerate --only-missing --yes
wp media regenerate 123 124 --image_size=large
wp media import ~/Downloads/photo.jpg --post_id=123 --title="Team photo" --featured_image
  • wp media image-size lists every registered size, so you can see what a regenerate will build.
  • --only-missing fills the gaps after a new size is added, without redoing every image.
  • A regenerate deletes old thumbnails by default. --skip-delete keeps them when other sites or emails link to those files.
  • --yes skips the confirmation prompt for a full run.

Posts, Options and wp-config.php

These are the everyday reads and edits. wp option get home belongs before any write, because it confirms which site the shell is pointed at.

wp post list --post_type=page --post_status=draft --fields=ID,post_title
wp post update 123 --post_status=publish
wp post delete 123
wp post delete 123 --force
wp option get home
wp option get siteurl
wp option update blogname "Example Site"
wp option list --autoload=on --format=total_bytes
wp config get DB_NAME
wp config set WP_DEBUG_LOG true --raw
wp config shuffle-salts
wp maintenance-mode activate
wp maintenance-mode deactivate
  • wp post delete moves a post to the trash. --force skips the trash and deletes it for good.
  • wp option list --autoload=on --format=total_bytes prints the total size of autoloaded options, which WordPress loads on every request.
  • wp config shuffle-salts replaces the keys and salts in wp-config.php, which logs every user out.
  • wp export writes a WXR file and wp import reads one, but import runs through the WordPress Importer plugin, so wp plugin install wordpress-importer --activate comes first.

Multisite and Remote Sites

On multisite, --url picks the subsite a command runs against, and without it WP-CLI works on the main site. Our WordPress multisite setup guide covers the network side.

wp site list --field=url
wp plugin list --url=https://example.com/blog/
wp site list --field=url | xargs -I % wp plugin list --url=%
wp core update-db --network

For other servers, aliases in wp-cli.yml save typing the SSH details each time. WP-CLI has to be installed on the remote server too.

@staging:
  ssh: deploy@staging.example.com
  path: /var/www/staging
@production:
  ssh: deploy@example.com
  path: /var/www/example.com
wp @staging plugin list
wp @production option get home

Global Flags

Global flags work with every command. Two flags people often treat as global, --dry-run and --format, belong to individual commands, so wp help is the place to check whether a command has them.

FlagWhat it does
--path=<path>Points WP-CLI at a WordPress folder
--url=<url>Picks the site, and the subsite on multisite
--ssh=<host>Runs the command on a remote server over SSH
--user=<id|login|email>Runs as a WordPress user, for capability checks
--skip-plugins[=<plugins>]Skips loading all plugins or the ones listed; mu-plugins still load
--skip-themes[=<themes>]Skips loading all themes or the ones listed
--skip-packagesSkips installed WP-CLI packages
--require=<path>Loads a PHP file before the command
--exec=<php-code>Runs PHP code before the command
--context=<context>Loads WordPress as cli or admin; the default auto uses admin for plugin and theme commands
--debug[=<group>]Shows PHP errors and extra WP-CLI output
--prompt[=<assoc>]Asks for argument values instead of reading them from the command line
--quietHides informational messages
--[no-]colorTurns colored output on or off

When WP-CLI Commands Fail

Most failures come from 4 places: the folder, the system user, the database or PHP itself. The error text usually says which one.

  • "This does not seem to be a WordPress installation": the folder has no core files. The install section above covers each cause.
  • "YIKES! It looks like you're running this as root": WP-CLI stops because plugin code would then run with full control of the server. sudo -u USER -i -- wp plugin list runs it as the site's own user instead.
  • "Error establishing a database connection": wp config get DB_HOST and wp db check show whether the credentials or the database server is the problem.
  • "Allowed memory size exhausted": with a Phar install, php -d memory_limit=512M "$(command -v wp)" media regenerate --yes raises the limit for one run. WP_CLI_PHP_ARGS only works for installs that don't use the Phar.
  • A plugin fatal error stops every command: wp plugin deactivate broken-plugin --skip-plugins --skip-themes loads WordPress without them, so the bad plugin can be switched off.

When none of those fit, --debug on the failing command shows each bootstrap step and every PHP notice. The last step printed before the error shows where loading stopped.

FAQs on WP-CLI Commands

What is WP-CLI?

WP-CLI is the official command-line interface for WordPress. It manages core, plugins, themes, users, the database, cron and multisite networks from a terminal, using the same WordPress code wp-admin runs.

How do I see every WP-CLI command?

wp help lists every command available on the site, including commands that plugins add. wp help plugin install shows every option for one command.

Can I use WP-CLI on shared hosting?

Yes, when the plan includes SSH access. Many hosts preinstall WP-CLI, and wp --info confirms it. Without it, the Phar file can live in your home folder with a shell alias.

Does wp plugin update --all put the site in maintenance mode?

Yes. WP-CLI turns maintenance mode on while it updates and off when the updates finish. If an update is cut off and the site stays in maintenance mode, wp maintenance-mode deactivate turns it off.

What is the difference between wp transient delete --expired and --all?

--expired removes only transients past their expiry, which is safe housekeeping. --all removes every transient, so plugins rebuild their cached data on the next requests.

How do I write a custom WP-CLI command?

WP_CLI::add_command() registers a command from a plugin or mu-plugin. It accepts a closure or a class, and WP_CLI::success() prints the result line.

How do I update WP-CLI itself?

wp cli update updates a Phar install, and wp cli version confirms the result. Homebrew and Composer installs update through those tools instead.

Final Remarks

If the terminal still feels risky, we'd start with the commands that only read: wp option get home, wp plugin list and wp db size --tables. From there, we'd add one write command at a time, each with a fresh wp db export before it.

Once those feel routine, the update sequence above is the one we'd turn into a script first.