Written by 6:50 am WP-CLI Views: 1

WP-CLI Commands Every Developer Should Know (With Cheatsheet)

Master the essential WP-CLI commands for WordPress management. Covers core updates, plugin management, database operations, user administration, cron jobs, and a complete quick-reference cheatsheet.

WP-CLI commands cheatsheet for WordPress developers showing terminal commands for plugins, database export, and search-replace

If you manage WordPress sites and you are still doing everything through the admin dashboard, you are working harder than you need to. WP-CLI is the official command-line interface for WordPress, and it lets you handle updates, database operations, user management, and dozens of other tasks in seconds instead of minutes. Once you start using it, going back to clicking through the dashboard feels painfully slow.

This guide covers the WP-CLI commands that matter most for day-to-day WordPress development and site management. Whether you are a developer, a freelancer managing client sites, or a sysadmin running WordPress at scale, these commands will save you significant time. We have organized them by category and included a cheatsheet table at the end for quick reference.


What Is WP-CLI and Why Should You Care?

WP-CLI stands for WordPress Command Line Interface. It is an open-source project maintained by the WordPress community that lets you interact with your WordPress installation directly from the terminal. Instead of logging into wp-admin, navigating menus, and clicking buttons, you type a single command and the action happens immediately.

The practical benefits are significant:

  • Speed — Updating 20 plugins takes one command instead of 20 clicks
  • Automation — Script repetitive tasks like backups, search-replace, and deployments
  • Batch operations — Create 50 test users, delete 10,000 spam comments, or bulk-update post metadata in seconds
  • Remote management — Run commands over SSH without opening a browser
  • Reliability — No browser timeouts on long-running operations like database imports

Installing WP-CLI

Most managed WordPress hosts (Cloudways, Kinsta, WP Engine, SiteGround) come with WP-CLI pre-installed. To check if it is available, SSH into your server and run:

wp --version

If it is not installed, you can install it manually on any Linux or macOS system. The official installation method from wp-cli.org:

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

After installation, run wp --info to confirm everything is working. You should see your PHP version, WordPress path, and WP-CLI version.


Core Commands: Managing WordPress Itself

These commands handle WordPress core updates, version checks, and installation.

# Check current WordPress version
wp core version

# Check if updates are available
wp core check-update

# Update WordPress core to the latest version
wp core update

# Update the database after a core update
wp core update-db

# Download and install WordPress from scratch
wp core download
wp core config --dbname=mydb --dbuser=myuser --dbpass=mypass
wp core install --url=example.com --title="My Site" --admin_user=admin [email protected]

The wp core install command is particularly useful for automated deployments. You can script an entire WordPress installation from download to first login in under 30 seconds.

Plugin Commands: Install, Update, and Manage Plugins

Plugin management is where WP-CLI saves the most time, especially when managing multiple sites.

# List all installed plugins with status and version
wp plugin list

# Install a plugin from wordpress.org
wp plugin install wordfence

# Install and activate in one step
wp plugin install rank-math-seo --activate

# Activate or deactivate a plugin
wp plugin activate akismet
wp plugin deactivate hello

# Update a specific plugin
wp plugin update woocommerce

# Update ALL plugins at once
wp plugin update --all

# Delete a plugin completely
wp plugin delete hello

# Search wordpress.org for plugins
wp plugin search "contact form" --fields=name,slug,rating

The wp plugin update --all command is a game-changer for maintenance. On a site with 25 plugins, this saves you from clicking “Update Now” 25 separate times in the dashboard. Combine it with wp core update and wp theme update --all for a complete update run in three commands.

Theme Commands: Switch and Manage Themes

# List installed themes
wp theme list

# Install a theme
wp theme install flavor starter theme astra

# Activate a theme
wp theme activate flavor starter theme flavor starter theme astra

# Update all themes
wp theme update --all

# Delete an inactive theme
wp theme delete flavor starter theme flavor starter theme flavor starter theme flavor twentytwentythree

# Get theme details
wp theme get flavor starter theme flavor starter theme flavor starter theme flavor astra

Database Commands: The Power Tools

Database commands are where WP-CLI becomes indispensable. Operations that are risky or impossible through the dashboard become straightforward.

# Export the entire database to a SQL file
wp db export backup.sql

# Import a database from a SQL file
wp db import backup.sql

# Search and replace across the entire database (with serialization handling)
wp search-replace 'http://old-domain.com' 'https://new-domain.com' --all-tables --dry-run
wp search-replace 'http://old-domain.com' 'https://new-domain.com' --all-tables

# Optimize database tables
wp db optimize

# Repair database tables
wp db repair

# Run a raw SQL query
wp db query "SELECT COUNT(*) FROM wp_posts WHERE post_type='post' AND post_status='publish'"

# Check database size
wp db size --tables

The wp search-replace command deserves special attention. When migrating a WordPress site from one domain to another, URLs are stored throughout the database — in posts, options, widgets, and serialized data. A simple SQL find-and-replace will break serialized data. WP-CLI’s search-replace command handles serialized data correctly, which makes it the safest way to migrate domains. Always run with --dry-run first to preview changes before committing.

User Commands: Create and Manage Users

# List all users
wp user list

# Create a new admin user
wp user create john [email protected] --role=administrator --user_pass=securepassword123

# Update a user's role
wp user set-role john editor

# Reset a user's password
wp user update john --user_pass=newpassword456

# Delete a user and reassign their posts
wp user delete john --reassign=1

# Generate test users (useful for development)
wp user generate --count=50 --role=subscriber

The wp user create command is a lifesaver when you get locked out of a WordPress site. If you have SSH access but cannot log in through wp-admin (maybe you forgot the password, or a security plugin locked you out), you can create a new admin user from the command line and regain access immediately.

Post and Content Commands

# List recent posts
wp post list --post_type=post --posts_per_page=10

# Create a new post
wp post create --post_title="My New Post" --post_status=draft --post_type=post

# Update a post's status
wp post update 123 --post_status=publish

# Delete a post (move to trash)
wp post delete 123

# Delete a post permanently
wp post delete 123 --force

# Delete all posts in trash
wp post delete $(wp post list --post_status=trash --format=ids) --force

# Generate test posts for development
wp post generate --count=100 --post_type=post --post_status=publish

Options and Configuration

# Get a WordPress option value
wp option get siteurl
wp option get blogname
wp option get permalink_structure

# Update an option
wp option update blogname "My Awesome Site"
wp option update permalink_structure '/%postname%/'

# List all autoloaded options (useful for performance debugging)
wp option list --autoload=yes --format=table

# Get total size of autoloaded options
wp option list --autoload=yes --format=csv | wc -l

Checking autoloaded options is a valuable performance debugging technique. WordPress loads all autoloaded options on every page request. If you have plugins storing large amounts of data as autoloaded options, it can slow down your site. Use this command to identify the biggest offenders.

Cache and Transients

# Flush the WordPress object cache
wp cache flush

# Delete all transients
wp transient delete --all

# Delete expired transients only
wp transient delete --expired

# List all transients
wp transient list

Flushing the cache and clearing transients is often the first troubleshooting step when something looks wrong after an update. If a page is showing stale content, a cached error, or a broken layout after a plugin update, wp cache flush combined with wp transient delete --all often resolves the issue.

Cron and Scheduled Tasks

# List all scheduled cron events
wp cron event list

# Run all due cron events now
wp cron event run --due-now

# Run a specific cron event
wp cron event run wp_update_plugins

# Test if WP-Cron is working
wp cron test

WordPress cron (WP-Cron) runs on page visits rather than on a real server schedule. On low-traffic sites, this means scheduled tasks might not run on time. Use wp cron event list to see what is scheduled and wp cron event run --due-now to manually trigger overdue events. For production sites, consider disabling WP-Cron (define('DISABLE_WP_CRON', true) in wp-config.php) and setting up a real server cron job that calls wp cron event run --due-now every few minutes.


Real-World Workflow: Staging to Production Migration

Here is a practical example of using WP-CLI commands together for a common task — migrating a WordPress site from a staging URL to a production URL:

# Step 1: Export the staging database
wp db export staging-backup.sql

# Step 2: Import on the production server
wp db import staging-backup.sql

# Step 3: Replace staging URLs with production URLs
wp search-replace 'https://staging.example.com' 'https://example.com' --all-tables --dry-run
wp search-replace 'https://staging.example.com' 'https://example.com' --all-tables

# Step 4: Flush caches and rewrite rules
wp cache flush
wp rewrite flush
wp transient delete --all

# Step 5: Verify the site URL
wp option get siteurl
wp option get home

This entire migration takes under 2 minutes from the command line. Doing the same through phpMyAdmin and the WordPress dashboard would take 15-20 minutes and carry a higher risk of breaking serialized data.

Quick Reference Cheatsheet

TaskCommand
Check WP versionwp core version
Update WordPresswp core update && wp core update-db
Update all pluginswp plugin update --all
Update all themeswp theme update --all
Export databasewp db export backup.sql
Import databasewp db import backup.sql
Search-replace URLswp search-replace 'old' 'new' --all-tables
Flush all cacheswp cache flush && wp transient delete --all
Create admin userwp user create name email --role=administrator
Reset user passwordwp user update username --user_pass=newpass
Flush rewrite ruleswp rewrite flush
List cron jobswp cron event list
Check autoloaded optionswp option list --autoload=yes
Delete spam commentswp comment delete $(wp comment list --status=spam --format=ids) --force
Generate test contentwp post generate --count=50

Tips for Getting the Most Out of WP-CLI

  1. Use –dry-run whenever available. Commands like search-replace support a dry-run flag that shows you what would change without actually changing anything. Always preview before committing.
  2. Pipe output to files. For large operations, redirect output: wp db export backup-$(date +%Y%m%d).sql creates timestamped backups automatically.
  3. Create aliases for multi-site management. WP-CLI supports an aliases.yml file that lets you define SSH connections to remote sites, so you can run commands on production from your local machine: wp @production plugin update --all.
  4. Combine with shell scripting. WP-CLI commands return standard exit codes and support --format=json output, making them easy to integrate into bash scripts and CI/CD pipelines.
  5. Keep WP-CLI updated. Run wp cli update periodically to get the latest commands and bug fixes.

When NOT to Use WP-CLI

WP-CLI is powerful, but it is not always the right tool. Avoid using it when:

  • You are on shared hosting without SSH access (some hosts offer WP-CLI through their dashboard, but this varies)
  • You are making one-off visual changes that are easier in the block editor
  • You need to preview content before publishing — the dashboard’s preview functionality has no CLI equivalent
  • You are working with clients who need to understand what you did — dashboard actions are more auditable for non-technical stakeholders

Further Resources

WP-CLI is one of those tools that once you learn, you wonder how you managed without it. Start with the basics — wp plugin update --all and wp db export — and gradually expand your command vocabulary. Within a week, you will be managing WordPress faster than you ever thought possible.

Visited 1 times, 1 visit(s) today

Last modified: April 2, 2026

Close