Skip to content

WordPress WP-CLI advanced commands — the 15 that earn their keep

Past wp plugin list and wp db export, WordPress WP-CLI ships 15 advanced commands that turn a one-off task into a script. The ones that actually move the needle in production.

Every WordPress operator knows wp plugin list and wp db export. The interesting layer is one level deeper — the WP-CLI commands that compose well in shell pipelines, run inside a loaded WordPress context, and replace 50 lines of bespoke PHP. Most teams use four of them and ignore the rest. Here are the 15 that earn their keep.

What’s happening

WP-CLI loads the same WordPress bootstrap as a web request — same plugins active, same hooks fired, same drop-ins respected. That’s what makes commands like wp eval and wp shell different from raw SQL: they see WordPress the way WordPress sees itself. The trade-off is startup cost (each invocation boots WordPress), which is why bulk loops chunk work and stream IDs.

How to verify

Confirm the WordPress WP-CLI install and the loaded context before running any of these:

wp --info
wp core version --extra
wp plugin list --status=active --fields=name,version --format=table
wp config get --constant WP_DEBUG

If wp --info shows a different PHP binary than the web server, the operations below run against a different WordPress runtime than visitors see — fix the PHP path before relying on the output.

What to do

The 15 commands that compose into real WordPress workflows:

  1. wp eval '<php>' — run inline PHP against the loaded WordPress. Use for one-line fixes: wp eval 'wp_cache_flush();' or wp eval 'echo wp_count_posts()->publish;'.
  2. wp eval-file <script.php> — same idea but for multi-line scripts you keep in version control next to the runbook.
  3. wp shell — interactive REPL with WordPress loaded. Useful for poking at $wpdb, exploring WP_Query results, and rehearsing an eval-file line by line.
  4. wp db query '<sql>' — runs SQL with credentials and prefix pulled from wp-config.php. Pair with --allow-root only on environments where the shell user really is the right identity.
  5. wp option pluck <key> <subkey> — walks into a serialized option without round-tripping through PHP. Faster than wp option get | jq on a 200KB option.
  6. wp option patch update <key> <subkey> <value> — writes into a serialized option without rewriting the entire array.
  7. wp post generate --count=N --post_type=... — fills staging with realistic content for load tests and editorial UAT.
  8. wp user generate --count=N --role=subscriber — pairs with the above for membership-flow staging.
  9. wp profile stage and wp profile hook — from the wp-cli/profile-command package. Identifies the slowest hook callbacks on a request, far faster than Query Monitor when you need a CLI answer.
  10. wp cron event run --due-now — drains the cron queue immediately without waiting for a real request. Pair with --quiet in cron jobs.
  11. wp transient delete --expired --all — clears stale transients without touching valid ones; respects the object cache drop-in unlike a raw DELETE FROM wp_options.
  12. wp search-replace --dry-run --recurse-objects --report-changed-only — the only safe way to preview a domain swap on serialized data before doing it.
  13. wp rewrite flush --hard — regenerates .htaccess on Apache; on Nginx it just flushes the rewrite rules. Run after any permalink structure change.
  14. wp media regenerate --yes --image_size=thumbnail — regenerate only the size you need, not every variant. Massive time saver on uploads-heavy sites.
  15. wp package install <name> — extends WP-CLI itself with community packages. wp-cli/find-command (finds WordPress installs on disk) and wp-cli/profile-command are the two we install on every operator account.

For a piped workflow that combines several of these, see WordPress fleet batch operations. For the surrounding deploy story, Stack Harbor’s enterprise WordPress operations practice ships these as muscle memory.

If a team’s WordPress operations still go through wp-admin clicks for everything, we can replatform the workflow.