7 WP-CLI Commands Every WordPress Developer Should Know
Source: Dev.to
[](https://dev.to/wpmultitool)
# Why WP‑CLI
If you manage WordPress sites and you're not using WP‑CLI, you're spending twice as long on routine tasks. WP‑CLI lets you manage everything from the terminal—updates, database operations, user management, configuration—without opening a browser.
For agencies managing 10+ sites, it's the difference between clicking through admin panels for an hour and running a script in 30 seconds.
Below are the commands I use most, split between core WP‑CLI and a few that require additional packages.
---The Essential 7
A quick reference for the most useful WP‑CLI commands. Each tip includes ready‑to‑run examples and optional safety notes.
1. wp core update + wp plugin update --all
# Update core, plugins, and themes in one go
wp core update && wp plugin update --all && wp theme update --allWith a backup first
wp db export ~/backups/$(date +%Y%m%d).sql && \
wp core update && wp plugin update --allBatch‑update multiple sites
for site in /var/www/site1 /var/www/site2 /var/www/site3; do
echo "=== Updating $site ==="
wp --path="$site" db export ~/backups/$(basename "$site")-$(date +%Y%m%d).sql
wp --path="$site" core update
wp --path="$site" plugin update --all
wp --path="$site" theme update --all
done2. wp db query
Run ad‑hoc SQL without phpMyAdmin.
# Check total autoload size
wp db query "SELECT SUM(LENGTH(option_value)) AS bytes \
FROM wp_options WHERE autoload='yes';"
# Show the 10 biggest autoloaded options
wp db query "SELECT option_name, LENGTH(option_value) AS size \
FROM wp_options WHERE autoload='yes' ORDER BY size DESC LIMIT 10;"
# Count post revisions
wp db query "SELECT COUNT(*) FROM wp_posts WHERE post_type='revision';"Tip: Pipe the output to grep, awk, or sed for further processing.
3. wp search-replace
Ideal for domain changes, HTTPS migrations, or moving from staging to production.
# Dry run – see what would change
wp search-replace 'http://staging.example.com' 'https://example.com' \
--all-tables --dry-run# Perform the replacement (handles serialized data)
wp search-replace 'http://staging.example.com' 'https://example.com' \
--all-tables4. wp cron event list + wp cron event run
Inspect and manually trigger WordPress cron jobs.
# List every scheduled event
wp cron event list# Run all overdue events
wp cron event run --due-now# Test a single hook
wp cron event run wp_scheduled_deleteProduction tip: Disable WP’s “fake” cron and let the system scheduler handle it.
// wp-config.php
define( 'DISABLE_WP_CRON', true );# Run WP‑CLI cron every 5 minutes
*/5 * * * * cd /var/www/site && wp cron event run --due-now --quiet5. wp transient delete --expired
Clear out stale transients that are still hanging around in the database.
# Remove only expired transients
wp transient delete --expired# Remove **all** transients (they’ll be regenerated as needed)
wp transient delete --allWhy it matters: Expired transients can accumulate to tens of thousands of rows, especially on WooCommerce or API‑heavy sites.
6. wp user list + wp user create
Manage users without touching the admin UI.
# List every administrator
wp user list --role=administrator \
--fields=ID,user_login,user_email# Create a temporary admin (use a strong password)
wp user create debuguser debug@example.com \
--role=administrator --user_pass=TempPass123!# Delete the temporary account and reassign its content to user ID 1
wp user delete debuguser --reassign=1Use case: Regain access when you’re locked out of the dashboard.
7. wp plugin list + wp plugin toggle
Quickly audit and toggle plugins.
# Show name, status, version, and update info
wp plugin list --fields=name,status,version,update# Deactivate then reactivate a single plugin (clears its runtime state)
wp plugin deactivate problematic-plugin && \
wp plugin activate problematic-plugin# Deactivate **all** plugins – great for debugging conflicts
wp plugin deactivate --allAfter deactivating everything, reactivate plugins one‑by‑one until the issue reappears to pinpoint the culprit.
Bonus: WP Multitool CLI Commands
WP Multitool adds seven sub‑commands that fill gaps in core WP‑CLI:
# Overall site health status
wp multitool status
# Database health report (table sizes, overhead, fragmentation)
wp multitool db-health
# Autoload analysis (size, top offenders, orphaned options)
wp multitool autoload --report
# Capture and analyze slow queries
wp multitool slow-queries --threshold=100
# Frontend optimization status
wp multitool frontend
# Run database cleanup (revisions, transients, orphaned data)
wp multitool clean --revisions --transients --orphaned
# Full health check (combines all above)
wp multitool healthcheckThese commands give you a quick, comprehensive snapshot of a site’s condition and let you perform routine clean‑ups with a single line.
Automation Template
Here’s a weekly maintenance script that combines everything:
#!/bin/bash
SITE="/var/www/yoursite"
BACKUP_DIR="$HOME/backups"
# Backup first
wp --path="$SITE" db export "$BACKUP_DIR/$(date +%Y%m%d).sql" --quiet
# Updates
wp --path="$SITE" plugin update --all --quiet
wp --path="$SITE" core update --quiet
# Cleanup
wp --path="$SITE" transient delete --expired --quiet
# Health check (requires WP Multitool)
wp --path="$SITE" multitool health
echo "Done: $(date)"Add it to cron, forget about it, and check the output when something feels off. That’s the WordPress maintenance workflow that actually scales.
Originally published at WP Multitool Blog.
Find what’s slowing your WordPress.
WP Multitool — 14 modules, $50 lifetime, zero bloat. Built by Marcin Dudek.