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.

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.

Core & Info

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

wp --info

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

wp --version

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

wp cli update

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

wp cli check-update

wp core version — Show the installed WordPress version.

wp core version

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

wp core check-update

Core Installation & Update

wp core download — Download the latest WordPress core files.

wp core download --locale=en_US

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

wp core download --version=6.5

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

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).

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.

wp core update

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

wp core update --version=6.5.2

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

wp core update-db

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

wp core verify-checksums

Plugins

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

wp plugin list

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

wp plugin install woocommerce

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

wp plugin install wordfence --activate

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

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

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

wp plugin activate woocommerce

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

wp plugin deactivate woocommerce

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

wp plugin deactivate --all

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

wp plugin delete hello-dolly

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

wp plugin update woocommerce

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

wp plugin update --all

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

wp plugin search 'security firewall'

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

wp plugin verify-checksums --all

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

wp plugin status woocommerce

Themes

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

wp theme list

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

wp theme install twentytwentyfour

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

wp theme install astra --activate

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

wp theme activate twentytwentyfour

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

wp theme delete twentytwentythree

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

wp theme update astra

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

wp theme update --all

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

wp theme status twentytwentyfour

Users

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

wp user list

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

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.

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.

wp user update 1 --user_pass=NewPassword123

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

wp user update 5 --role=administrator

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

wp user delete 5 --reassign=1

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

wp user get 1

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

wp user list --role=administrator

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

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

Posts & Content

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

wp post list

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

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.

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.

wp post update 42 --post_status=draft

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

wp post delete 42

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

wp post delete 42 --force

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

wp post get 42

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

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.

wp post meta list 42

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

wp post meta update 42 _thumbnail_id 99

Options (wp_options)

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

wp option get siteurl

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

wp option update blogname 'My New Site Name'

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

wp option list

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

wp option list --search='siteurl'

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

wp option delete deprecated_setting

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

wp option add my_custom_option 'value123'

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

wp option get active_plugins --format=json

Database

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

wp db export backup.sql

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

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

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

wp db import backup.sql

wp db optimize — Optimize all database tables.

wp db optimize

wp db repair — Repair all database tables.

wp db repair

wp db size — Show the total database size.

wp db size

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

wp db size --tables

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

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.

wp db cli

wp db check — Check all database tables for errors.

wp db check

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

wp db tables

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

wp db reset --yes

Search & Replace

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

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.

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.

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.

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.

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.

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

Cache & Transients

wp cache flush — Flush the WordPress object cache.

wp cache flush

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

wp transient delete --all

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

wp transient delete --expired

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

wp transient get my_cached_data

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

wp rewrite flush

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

wp rewrite structure '/%postname%/'

Media & Uploads

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

wp media regenerate --yes

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

wp media regenerate --only-missing

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

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

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

wp media image-size

Maintenance & Multisite

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

wp cron event list

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

wp cron event run --all

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

wp cron event run wp_scheduled_auto_draft_delete

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

wp cron test

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

wp maintenance-mode activate

wp maintenance-mode deactivate — Disable maintenance mode.

wp maintenance-mode deactivate

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

wp site list

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

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

Scaffolding & Export

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

wp scaffold plugin my-custom-plugin

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

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

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

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

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

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

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

wp export --dir=./exports/

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

wp import export.xml --authors=create

Output Formats & Global Flags

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

wp plugin list --format=table

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

wp plugin list --format=json

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

wp user list --format=csv

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

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

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

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

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

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

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

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.

wp option get siteurl --skip-plugins

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

wp core version --skip-themes

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

  • artisan – command-line interface for the Laravel PHP framework
  • cargo – build tool and package manager for Rust
  • composer – dependency manager for PHP projects