easythemestore

The Best WordPress CLI Commands You’re Not Using

The Best WordPress CLI Commands You’re Not Using (But Should)

The WordPress Command Line Interface (WP-CLI) is a powerful tool for developers and sysadmins—but most users only scratch the surface with basic wp core install or wp plugin update commands.

Here are 10 underused WP-CLI commands that can save hours of manual work, automate tedious tasks, and unlock advanced WordPress management.


1. Reset All Passwords (wp user reset-password)

Forgot all user passwords? Reset them in bulk:
wp user reset-password –all

Use Case:

  • Quickly recover access after a security incident. Our YouTube channel; https://www.youtube.com/@easythemestore


2. Find & Replace in Database (wp search-replace)

Safer than manual SQL queries:
wp search-replace “old-url.com” “new-url.com” –all-tables –dry-run

Flags:

  • --dry-run (test first)
  • --precise (slower but more accurate)

3. Generate Fake Content (wp faker)

Need dummy posts for testing? Install WP Faker:

wp plugin install wp-faker --activate
wp faker generate posts --count=50

Options:

  • --post_type=product (for WooCommerce)
  • --with-thumbnails (attach images)

4. Optimize WordPress Images (wp media regenerate)

Resize & compress all existing images:
wp media regenerate –yes –only-missing

Bonus: Add --image_size=large to target specific sizes.


5. Bulk Delete Spam Comments (wp comment delete)

wp comment delete $(wp comment list --status=spam --format=ids)

Alternative: Delete old comments (30+ days):

wp comment delete $(wp comment list --before="30 days ago" --format=ids)

6. List All Cron Events (wp cron event list)

Debug scheduled tasks:
wp cron event list –format=table

Run a specific cron job manually:
wp cron event run “wp_update_plugins”


7. Export Any WordPress Data (wp export)

Custom XML exports (like PHPMyAdmin but safer):
wp export –post_type=post –start_date=2024-01-01

Filter by:

  • --author=admin
  • --post_status=publish

8. Find Performance Hogs (wp profile stage)

Debug slow plugins/themes:
wp profile stage –spotlight

Outputs:

  • Slow hooks (wp profile hook)
  • Heavy queries (wp profile db)

9. Bulk Change User Roles (wp user update)

wp user update $(wp user list --role=subscriber --field=ID) --role=customer

Use Case:

  • Migrate Subscribers to Customers (WooCommerce).


10. Run PHP Code Directly (wp eval)

Quickly test snippets without editing files:

wp eval 'echo wp_get_theme()->get("Version");'

Advanced Example:

wp eval 'wp_insert_post(["post_title" => "Test", "post_status" => "publish"]);'

Bonus: Custom WP-CLI Commands

Create your own commands (save in wp-content/mu-plugins/cli-commands.php):

<?php
WP_CLI::add_command('hello', function($args) {
    WP_CLI::success("Hello, " . $args[0] . "!");
});

Usage:

wp hello John
# Output: Success: Hello, John!

When to Use These Commands?

TaskCommand
Staging site migrationwp search-replace
Performance debuggingwp profile stage
Bulk content generationwp faker
Emergency password resetwp user reset-password --all

💡 Pro Tip: Chain commands with && for automation:

wp plugin update --all && wp core update && wp cache flush

🚀 Master these, and you’ll never manage WordPress manually again!