iwantcoding.com
🔥 Daily 👥 Rooms 🏆 Top Log in Sign up

WP-CLI

WP-CLI is the official command-line interface for WordPress. Anything you can do in wp-admin you can script with WP-CLI, plus a lot you cannot — bulk user creation, search-replace across serialized data during host migrations, plugin updates from CI. If you administer WordPress without WP-CLI you are working with one hand.

A practical WP-CLI cheat sheet

EXAMPLE
# 1) Health check the install
wp core verify-checksums
wp plugin verify-checksums --all
wp cron event list --due-now
wp db check

# 2) Core, plugin, theme updates from a deploy script
wp core update --version=6.6.2 --locale=en_AU
wp plugin update --all --exclude=woocommerce
wp theme update --all
wp core update-db

# 3) Search-replace during a host or domain migration (handles serialized data)
wp search-replace 'https://staging.example.com' 'https://example.com' \
  --all-tables --report-changed-only --dry-run
# Drop --dry-run when the report looks right.

# 4) Bulk content tasks
wp post list --post_type=post --posts_per_page=-1 \
  --field=ID --post_status=draft \
| xargs -L1 -I{} wp post update {} --post_status=publish

# 5) User management without clicking
wp user create alice alice@example.com --role=editor --send-email
wp user reset-password bob --skip-email
wp role list --format=table
wp cap add editor edit_others_posts

# 6) Export/import for backups or content seeding
wp db export backup-$(date +%F).sql
wp db import backup-2026-06-11.sql

# 7) Maintenance mode around a long task
wp maintenance-mode activate
wp plugin update --all
wp core update-db
wp maintenance-mode deactivate

# 8) One-off PHP — handy in incident response
wp eval 'wp_cache_flush(); echo "flushed\n";'
wp eval-file scripts/fix-orphaned-attachments.php

# 9) Run it through SSH on a managed host
wp --ssh=user@web1.example.com:/var/www/example.com plugin list

Why it matters

For non-trivial changes — search-replace on production, plugin updates, role changes — always run with --dry-run or in a staging clone first. WP-CLI does what you ask without the wp-admin "Are you sure?" guardrails, which is its strength and its sharp edge.

Tip: Tweak the snippet with Try it Yourself », then sit the quiz at the bottom of the page.

Example

Example
wp plugin install woocommerce --activate
wp post list
wp db export backup.sql
Try it Yourself »

Exercise

Install a plugin from the CLI.

wp install akismet --activate

Test yourself

Q1. WP-CLI is…
Q2. Install a plugin from the command line with…
Q3. Search-replace URLs across the DB safely with…

Discussion

Loading…