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 --infoRun in a specific path
wp --path=/home/user/public_html core versionUse as account user
su - user -c 'wp --path=/home/user/public_html plugin list'Skip plugins/themes
wp --skip-plugins --skip-themes option get siteurlCore
| Task | Command |
|---|---|
| Show WordPress version | wp core version |
| Check for core updates | wp core check-update |
| Update core | wp core update |
| Verify core files | wp core verify-checksums |
| Show site URL | wp option get siteurl |
Plugins and themes
List plugins
wp plugin listUpdate all plugins
wp plugin update --allDeactivate plugin
wp plugin deactivate plugin-slugList themes
wp theme listUpdate all themes
wp theme update --allActivate theme
wp theme activate twentytwentyfourUsers
| Task | Command |
|---|---|
| List users | wp user list |
| Show admins | wp user list --role=administrator |
| Reset password | wp user update admin --user_pass='NewStrongPassword' |
| Create admin | wp user create support support@example.com --role=administrator --user_pass='StrongPassword' |
Database
Export database
wp db export backup.sqlImport database
wp db import backup.sqlRepair database
wp db repairOptimize database
wp db optimizeSearch 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
| Option | Use |
|---|---|
--dry-run | Preview changes only. |
--all-tables | Include tables outside the registered WP tables. |
--precise | Safer for serialized data, but slower. |
--skip-columns=guid | Common option when avoiding GUID changes. |
Cache and cron
Flush object cache
wp cache flushList cron events
wp cron event listRun due cron
wp cron event run --due-nowRun one hook
wp cron event run hook_nameTroubleshooting
- Use
--skip-plugins --skip-themeswhen 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
WP-CLI workflows for maintenance
Pre-update checks
wp core version
wp plugin list --update=available
wp theme list --update=availableBackup database
wp db export before-maintenance.sqlSafe search replace
wp search-replace 'http://old.example.com' 'https://new.example.com' --dry-runFlush cache
wp cache flushFrequently 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.