# WP-CLI — Manage WordPress from the Command Line

> Practical guide to WP-CLI — manage WordPress plugins, themes, core, users and the database from the command line, without a browser.

Source: https://www.jpkc.com/db/en/cheatsheets/build-languages/wp-cli/

<!-- PROSE:intro -->
WP-CLI is the official command-line tool for WordPress, driven by the `wp` binary. It lets you manage plugins, themes, core, the database and users without ever opening a browser – ideal for automation, maintenance and bulk operations, whether on a single site or an entire Multisite network. This guide collects the commands you reach for most, from installing WordPress to search-replacing a domain across the whole database.
<!-- PROSE:intro:end -->

## Core & Info

`wp --info` — Show information about the WP-CLI environment (PHP version, paths, OS).

```bash
wp --info
```

`wp --version` — Show the installed WP-CLI version.

```bash
wp --version
```

`wp cli update` — Update WP-CLI to the latest stable version.

```bash
wp cli update
```

`wp cli check-update` — Check if a newer version of WP-CLI is available.

```bash
wp cli check-update
```

`wp core version` — Show the installed WordPress version.

```bash
wp core version
```

`wp core check-update` — Check if WordPress core updates are available.

```bash
wp core check-update
```

## Core Installation & Update

`wp core download` — Download the latest WordPress core files.

```bash
wp core download --locale=en_US
```

`wp core download --version=<version>` — Download a specific WordPress version.

```bash
wp core download --version=6.5
```

`wp core config --dbname=<db> --dbuser=<user> --dbpass=<pass>` — Generate a wp-config.php file with database credentials.

```bash
wp core config --dbname=wordpress --dbuser=root --dbpass=secret --dbhost=localhost
```

`wp core install --url=<url> --title=<title> --admin_user=<user> --admin_password=<pass> --admin_email=<email>` — Run the WordPress installation (create tables, set up admin account).

```bash
wp core install --url=example.com --title='My Site' --admin_user=admin --admin_password=secret --admin_email=admin@example.com
```

`wp core update` — Update WordPress core to the latest version.

```bash
wp core update
```

`wp core update --version=<version>` — Update to a specific WordPress version.

```bash
wp core update --version=6.5.2
```

`wp core update-db` — Run the database upgrade routine after a core update.

```bash
wp core update-db
```

`wp core verify-checksums` — Verify WordPress core files against their checksums. Detects modified or infected files.

```bash
wp core verify-checksums
```

## Plugins

`wp plugin list` — List all installed plugins with name, status, update availability, and version.

```bash
wp plugin list
```

`wp plugin install <plugin>` — Install a plugin from the WordPress.org repository.

```bash
wp plugin install woocommerce
```

`wp plugin install <plugin> --activate` — Install and immediately activate a plugin.

```bash
wp plugin install wordfence --activate
```

`wp plugin install <url>` — Install a plugin from a ZIP URL.

```bash
wp plugin install https://example.com/my-plugin.zip --activate
```

`wp plugin activate <plugin>` — Activate an installed plugin.

```bash
wp plugin activate woocommerce
```

`wp plugin deactivate <plugin>` — Deactivate a plugin without removing it.

```bash
wp plugin deactivate woocommerce
```

`wp plugin deactivate --all` — Deactivate all plugins at once. Useful for debugging.

```bash
wp plugin deactivate --all
```

`wp plugin delete <plugin>` — Delete a plugin (deactivates if needed and removes files).

```bash
wp plugin delete hello-dolly
```

`wp plugin update <plugin>` — Update a specific plugin to the latest version.

```bash
wp plugin update woocommerce
```

`wp plugin update --all` — Update all installed plugins.

```bash
wp plugin update --all
```

`wp plugin search <keyword>` — Search the WordPress.org plugin repository.

```bash
wp plugin search 'security firewall'
```

`wp plugin verify-checksums --all` — Verify plugin files against WordPress.org checksums to detect tampering.

```bash
wp plugin verify-checksums --all
```

`wp plugin status <plugin>` — Show detailed status information about a plugin.

```bash
wp plugin status woocommerce
```

## Themes

`wp theme list` — List all installed themes with status, update availability, and version.

```bash
wp theme list
```

`wp theme install <theme>` — Install a theme from the WordPress.org repository.

```bash
wp theme install twentytwentyfour
```

`wp theme install <theme> --activate` — Install and immediately activate a theme.

```bash
wp theme install astra --activate
```

`wp theme activate <theme>` — Activate an installed theme.

```bash
wp theme activate twentytwentyfour
```

`wp theme delete <theme>` — Delete an inactive theme.

```bash
wp theme delete twentytwentythree
```

`wp theme update <theme>` — Update a specific theme.

```bash
wp theme update astra
```

`wp theme update --all` — Update all installed themes.

```bash
wp theme update --all
```

`wp theme status <theme>` — Show detailed information about a theme.

```bash
wp theme status twentytwentyfour
```

## Users

`wp user list` — List all users with ID, login, email, and role.

```bash
wp user list
```

`wp user create <login> <email> --role=<role>` — Create a new user with a specific role.

```bash
wp user create editor editor@example.com --role=editor
```

`wp user create <login> <email> --role=administrator --user_pass=<pass>` — Create a new admin user with a specific password.

```bash
wp user create newadmin admin@example.com --role=administrator --user_pass=StrongPass123
```

`wp user update <user_id> --user_pass=<pass>` — Reset a user's password.

```bash
wp user update 1 --user_pass=NewPassword123
```

`wp user update <user_id> --role=<role>` — Change a user's role.

```bash
wp user update 5 --role=administrator
```

`wp user delete <user_id>` — Delete a user. Prompts for content reassignment.

```bash
wp user delete 5 --reassign=1
```

`wp user get <user_id>` — Show detailed information about a specific user.

```bash
wp user get 1
```

`wp user list --role=administrator` — List all users with a specific role.

```bash
wp user list --role=administrator
```

`wp user generate --count=<n> --role=<role>` — Generate dummy users for testing.

```bash
wp user generate --count=10 --role=subscriber
```

## Posts & Content

`wp post list` — List all posts with ID, title, status, and date.

```bash
wp post list
```

`wp post list --post_type=<type> --post_status=<status>` — List posts filtered by type and status.

```bash
wp post list --post_type=page --post_status=draft
```

`wp post create --post_title='<title>' --post_status=publish` — Create a new post and publish it immediately.

```bash
wp post create --post_title='Hello World' --post_content='My first post.' --post_status=publish
```

`wp post update <post_id> --post_status=<status>` — Update a post's status or other fields.

```bash
wp post update 42 --post_status=draft
```

`wp post delete <post_id>` — Move a post to the trash.

```bash
wp post delete 42
```

`wp post delete <post_id> --force` — Permanently delete a post (bypass trash).

```bash
wp post delete 42 --force
```

`wp post get <post_id>` — Show detailed information about a specific post.

```bash
wp post get 42
```

`wp post generate --count=<n>` — Generate dummy posts for testing.

```bash
wp post generate --count=50 --post_type=post --post_status=publish
```

`wp post meta list <post_id>` — List all meta fields for a specific post.

```bash
wp post meta list 42
```

`wp post meta update <post_id> <key> <value>` — Update or add a post meta field.

```bash
wp post meta update 42 _thumbnail_id 99
```

## Options (wp_options)

`wp option get <key>` — Get the value of a specific WordPress option.

```bash
wp option get siteurl
```

`wp option update <key> <value>` — Update a WordPress option.

```bash
wp option update blogname 'My New Site Name'
```

`wp option list` — List all options in the wp_options table.

```bash
wp option list
```

`wp option list --search='<pattern>'` — Search for options matching a pattern.

```bash
wp option list --search='siteurl'
```

`wp option delete <key>` — Delete a specific option from the database.

```bash
wp option delete deprecated_setting
```

`wp option add <key> <value>` — Add a new option to the database.

```bash
wp option add my_custom_option 'value123'
```

`wp option get <key> --format=json` — Get a serialized option value formatted as JSON.

```bash
wp option get active_plugins --format=json
```

## Database

`wp db export <file>` — Export the database to a SQL file.

```bash
wp db export backup.sql
```

`wp db export - | gzip > <file>` — Export the database and compress it with gzip.

```bash
wp db export - | gzip > backup.sql.gz
```

`wp db import <file>` — Import a SQL file into the database.

```bash
wp db import backup.sql
```

`wp db optimize` — Optimize all database tables.

```bash
wp db optimize
```

`wp db repair` — Repair all database tables.

```bash
wp db repair
```

`wp db size` — Show the total database size.

```bash
wp db size
```

`wp db size --tables` — Show the size of each individual table.

```bash
wp db size --tables
```

`wp db query '<sql>'` — Execute a raw SQL query on the database.

```bash
wp db query 'SELECT COUNT(*) FROM wp_posts WHERE post_status="publish"'
```

`wp db cli` — Open an interactive MySQL/MariaDB shell for the WordPress database.

```bash
wp db cli
```

`wp db check` — Check all database tables for errors.

```bash
wp db check
```

`wp db tables` — List all tables in the WordPress database.

```bash
wp db tables
```

`wp db reset --yes` — Drop all tables and recreate them from the schema. Destroys all data.

```bash
wp db reset --yes
```

## Search & Replace

`wp search-replace '<old>' '<new>'` — Search and replace across all database tables. Handles serialized data correctly.

```bash
wp search-replace 'http://old-domain.com' 'https://new-domain.com'
```

`wp search-replace '<old>' '<new>' --dry-run` — Preview how many replacements would be made without changing anything.

```bash
wp search-replace 'http://old-domain.com' 'https://new-domain.com' --dry-run
```

`wp search-replace '<old>' '<new>' <table>` — Limit the search-replace to specific tables.

```bash
wp search-replace 'http://old.com' 'https://new.com' wp_posts wp_postmeta
```

`wp search-replace '<old>' '<new>' --precise` — Use precise mode for more accurate serialized data handling.

```bash
wp search-replace 'old-domain.com' 'new-domain.com' --precise
```

`wp search-replace '<old>' '<new>' --all-tables` — Search-replace across all tables including non-WordPress tables.

```bash
wp search-replace 'staging.example.com' 'www.example.com' --all-tables
```

`wp search-replace '<old>' '<new>' --export=<file>` — Export the result as a SQL file instead of modifying the database directly.

```bash
wp search-replace 'http://dev.local' 'https://www.example.com' --export=migrated.sql
```

## Cache & Transients

`wp cache flush` — Flush the WordPress object cache.

```bash
wp cache flush
```

`wp transient delete --all` — Delete all transients from the database.

```bash
wp transient delete --all
```

`wp transient delete --expired` — Delete only expired transients.

```bash
wp transient delete --expired
```

`wp transient get <key>` — Get the value of a specific transient.

```bash
wp transient get my_cached_data
```

`wp rewrite flush` — Flush and regenerate rewrite rules (fixes permalink issues).

```bash
wp rewrite flush
```

`wp rewrite structure '<structure>'` — Set the permalink structure.

```bash
wp rewrite structure '/%postname%/'
```

## Media & Uploads

`wp media regenerate` — Regenerate all image thumbnails. Useful after changing theme or image sizes.

```bash
wp media regenerate --yes
```

`wp media regenerate --only-missing` — Only regenerate missing image sizes (faster than full regeneration).

```bash
wp media regenerate --only-missing
```

`wp media import <file_or_url>` — Import a file or URL as an attachment into the media library.

```bash
wp media import ./photo.jpg --title='My Photo'
```

`wp media image-size` — List all registered image sizes.

```bash
wp media image-size
```

## Maintenance & Multisite

`wp cron event list` — List all scheduled cron events with their next run time.

```bash
wp cron event list
```

`wp cron event run --all` — Run all pending cron events immediately.

```bash
wp cron event run --all
```

`wp cron event run <hook>` — Run a specific cron event by its hook name.

```bash
wp cron event run wp_scheduled_auto_draft_delete
```

`wp cron test` — Test if the WP-Cron spawning system is working correctly.

```bash
wp cron test
```

`wp maintenance-mode activate` — Enable maintenance mode (shows maintenance page to visitors).

```bash
wp maintenance-mode activate
```

`wp maintenance-mode deactivate` — Disable maintenance mode.

```bash
wp maintenance-mode deactivate
```

`wp site list` — List all sites in a WordPress Multisite network.

```bash
wp site list
```

`wp --url=<site_url> <command>` — Run a WP-CLI command against a specific site in a Multisite network.

```bash
wp --url=subsite.example.com plugin list
```

## Scaffolding & Export

`wp scaffold plugin <slug>` — Generate boilerplate files for a new plugin.

```bash
wp scaffold plugin my-custom-plugin
```

`wp scaffold child-theme <slug> --parent_theme=<parent>` — Generate a child theme.

```bash
wp scaffold child-theme my-child --parent_theme=twentytwentyfour
```

`wp scaffold post-type <slug> --plugin=<plugin>` — Generate code for a custom post type.

```bash
wp scaffold post-type product --plugin=my-custom-plugin --label=Product
```

`wp scaffold taxonomy <slug> --post_types=<types>` — Generate code for a custom taxonomy.

```bash
wp scaffold taxonomy genre --post_types=book --plugin=my-custom-plugin
```

`wp export` — Export content to a WordPress eXtended RSS (WXR) XML file.

```bash
wp export --dir=./exports/
```

`wp import <file> --authors=create` — Import content from a WXR XML file.

```bash
wp import export.xml --authors=create
```

## Output Formats & Global Flags

`wp <command> --format=table` — Output as an ASCII table (default format).

```bash
wp plugin list --format=table
```

`wp <command> --format=json` — Output as a JSON array.

```bash
wp plugin list --format=json
```

`wp <command> --format=csv` — Output as comma-separated values.

```bash
wp user list --format=csv
```

`wp <command> --format=ids` — Output only the IDs, space-separated. Useful for piping.

```bash
wp post list --post_type=revision --format=ids | xargs wp post delete
```

`wp <command> --fields=<field1>,<field2>` — Limit output to specific columns.

```bash
wp plugin list --fields=name,status,version
```

`wp <command> --path=<path>` — Run WP-CLI against a WordPress installation at a specific path.

```bash
wp core version --path=/var/www/html
```

`wp <command> --ssh=<host>` — Run WP-CLI on a remote server via SSH.

```bash
wp plugin list --ssh=deploy@server.example.com:/var/www/html
```

`wp <command> --skip-plugins` — Run without loading plugins. Useful when a plugin causes fatal errors.

```bash
wp option get siteurl --skip-plugins
```

`wp <command> --skip-themes` — Run without loading the active theme.

```bash
wp core version --skip-themes
```

<!-- PROSE:outro -->
## Conclusion

WP-CLI turns repetitive WordPress chores into single, scriptable commands – updates, backups, migrations and user management all run straight from the shell. Treat the destructive commands with care: `wp db reset`, `wp db drop` and `wp site empty` wipe content and tables irreversibly, and `--yes` skips the safety prompt. Always run `wp search-replace` with `--dry-run` first, and double-check `wp user delete` before you confirm. Avoid running `wp` as root – reach for `--allow-root` only deliberately, and only where you fully understand the consequences.

## Further Reading

- [WP-CLI Handbook](https://make.wordpress.org/cli/handbook/) – official documentation, guides and command reference
- [developer.wordpress.org/cli](https://developer.wordpress.org/cli/commands/) – full command reference on the WordPress Developer site
- [wp-cli.org](https://wp-cli.org/) – the project home page
<!-- PROSE:outro:end -->

## Related Commands

- [artisan](https://www.jpkc.com/db/en/cheatsheets/build-languages/artisan/) – command-line interface for the Laravel PHP framework
- [cargo](https://www.jpkc.com/db/en/cheatsheets/build-languages/cargo/) – build tool and package manager for Rust
- [composer](https://www.jpkc.com/db/en/cheatsheets/build-languages/composer/) – dependency manager for PHP projects

