WordPress CLI

WP-CLI Cheat Sheet

Run WordPress maintenance from the command line: check core, manage plugins, export databases, search-replace URLs, flush cache, inspect cron and troubleshoot common problems.

Getting started

Check WP-CLI works

wp --info

Run in a specific path

wp --path=/home/user/public_html core version

Use as account user

su - user -c 'wp --path=/home/user/public_html plugin list'

Skip plugins/themes

wp --skip-plugins --skip-themes option get siteurl

Core

TaskCommand
Show WordPress versionwp core version
Check for core updateswp core check-update
Update corewp core update
Verify core fileswp core verify-checksums
Show site URLwp option get siteurl

Plugins and themes

List plugins

wp plugin list

Update all plugins

wp plugin update --all

Deactivate plugin

wp plugin deactivate plugin-slug

List themes

wp theme list

Update all themes

wp theme update --all

Activate theme

wp theme activate twentytwentyfour

Users

TaskCommand
List userswp user list
Show adminswp user list --role=administrator
Reset passwordwp user update admin --user_pass='NewStrongPassword'
Create adminwp user create support support@example.com --role=administrator --user_pass='StrongPassword'

Database

Export database

wp db export backup.sql

Import database

wp db import backup.sql

Repair database

wp db repair

Optimize database

wp db optimize

Search replace

Always dry-run first: search-replace can make large database changes quickly.
wp search-replace 'http://oldsite.com' 'https://newsite.com' --dry-run
wp search-replace 'http://oldsite.com' 'https://newsite.com' --all-tables --precise
OptionUse
--dry-runPreview changes only.
--all-tablesInclude tables outside the registered WP tables.
--preciseSafer for serialized data, but slower.
--skip-columns=guidCommon option when avoiding GUID changes.

Cache and cron

Flush object cache

wp cache flush

List cron events

wp cron event list

Run due cron

wp cron event run --due-now

Run one hook

wp cron event run hook_name

Troubleshooting

  • Use --skip-plugins --skip-themes when a broken plugin or theme prevents WP-CLI loading.
  • Run as the account user where possible, not root.
  • Use --path= if you are not already in the WordPress document root.
  • Export the database before large changes.
wp --path=/home/user/public_html --skip-plugins --skip-themes option get home
WordPress workflows

WP-CLI workflows for maintenance

Pre-update checks

wp core version
wp plugin list --update=available
wp theme list --update=available

Backup database

wp db export before-maintenance.sql

Safe search replace

wp search-replace 'http://old.example.com' 'https://new.example.com' --dry-run

Flush cache

wp cache flush
FAQ

Frequently Asked Questions

What is WP-CLI used for?

WP-CLI manages WordPress from the command line, including plugins, themes, users, options, databases and maintenance tasks.

Should I run wp db export before changes?

Yes, export the database before updates or search-replace tasks.

Why use --dry-run with search-replace?

--dry-run previews the changes without writing to the database.

Where should I run WP-CLI commands?

Run them from the WordPress document root or specify the path with --path.