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 --infowp --version — Show the installed WP-CLI version.
wp --versionwp cli update — Update WP-CLI to the latest stable version.
wp cli updatewp cli check-update — Check if a newer version of WP-CLI is available.
wp cli check-updatewp core version — Show the installed WordPress version.
wp core versionwp core check-update — Check if WordPress core updates are available.
wp core check-updateCore Installation & Update
wp core download — Download the latest WordPress core files.
wp core download --locale=en_USwp core download --version=<version> — Download a specific WordPress version.
wp core download --version=6.5wp 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=localhostwp 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.comwp core update — Update WordPress core to the latest version.
wp core updatewp core update --version=<version> — Update to a specific WordPress version.
wp core update --version=6.5.2wp core update-db — Run the database upgrade routine after a core update.
wp core update-dbwp core verify-checksums — Verify WordPress core files against their checksums. Detects modified or infected files.
wp core verify-checksumsPlugins
wp plugin list — List all installed plugins with name, status, update availability, and version.
wp plugin listwp plugin install <plugin> — Install a plugin from the WordPress.org repository.
wp plugin install woocommercewp plugin install <plugin> --activate — Install and immediately activate a plugin.
wp plugin install wordfence --activatewp plugin install <url> — Install a plugin from a ZIP URL.
wp plugin install https://example.com/my-plugin.zip --activatewp plugin activate <plugin> — Activate an installed plugin.
wp plugin activate woocommercewp plugin deactivate <plugin> — Deactivate a plugin without removing it.
wp plugin deactivate woocommercewp plugin deactivate --all — Deactivate all plugins at once. Useful for debugging.
wp plugin deactivate --allwp plugin delete <plugin> — Delete a plugin (deactivates if needed and removes files).
wp plugin delete hello-dollywp plugin update <plugin> — Update a specific plugin to the latest version.
wp plugin update woocommercewp plugin update --all — Update all installed plugins.
wp plugin update --allwp 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 --allwp plugin status <plugin> — Show detailed status information about a plugin.
wp plugin status woocommerceThemes
wp theme list — List all installed themes with status, update availability, and version.
wp theme listwp theme install <theme> — Install a theme from the WordPress.org repository.
wp theme install twentytwentyfourwp theme install <theme> --activate — Install and immediately activate a theme.
wp theme install astra --activatewp theme activate <theme> — Activate an installed theme.
wp theme activate twentytwentyfourwp theme delete <theme> — Delete an inactive theme.
wp theme delete twentytwentythreewp theme update <theme> — Update a specific theme.
wp theme update astrawp theme update --all — Update all installed themes.
wp theme update --allwp theme status <theme> — Show detailed information about a theme.
wp theme status twentytwentyfourUsers
wp user list — List all users with ID, login, email, and role.
wp user listwp user create <login> <email> --role=<role> — Create a new user with a specific role.
wp user create editor editor@example.com --role=editorwp 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=StrongPass123wp user update <user_id> --user_pass=<pass> — Reset a user's password.
wp user update 1 --user_pass=NewPassword123wp user update <user_id> --role=<role> — Change a user's role.
wp user update 5 --role=administratorwp user delete <user_id> — Delete a user. Prompts for content reassignment.
wp user delete 5 --reassign=1wp user get <user_id> — Show detailed information about a specific user.
wp user get 1wp user list --role=administrator — List all users with a specific role.
wp user list --role=administratorwp user generate --count=<n> --role=<role> — Generate dummy users for testing.
wp user generate --count=10 --role=subscriberPosts & Content
wp post list — List all posts with ID, title, status, and date.
wp post listwp post list --post_type=<type> --post_status=<status> — List posts filtered by type and status.
wp post list --post_type=page --post_status=draftwp 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=publishwp post update <post_id> --post_status=<status> — Update a post's status or other fields.
wp post update 42 --post_status=draftwp post delete <post_id> — Move a post to the trash.
wp post delete 42wp post delete <post_id> --force — Permanently delete a post (bypass trash).
wp post delete 42 --forcewp post get <post_id> — Show detailed information about a specific post.
wp post get 42wp post generate --count=<n> — Generate dummy posts for testing.
wp post generate --count=50 --post_type=post --post_status=publishwp post meta list <post_id> — List all meta fields for a specific post.
wp post meta list 42wp post meta update <post_id> <key> <value> — Update or add a post meta field.
wp post meta update 42 _thumbnail_id 99Options (wp_options)
wp option get <key> — Get the value of a specific WordPress option.
wp option get siteurlwp 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 listwp 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_settingwp 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=jsonDatabase
wp db export <file> — Export the database to a SQL file.
wp db export backup.sqlwp db export - | gzip > <file> — Export the database and compress it with gzip.
wp db export - | gzip > backup.sql.gzwp db import <file> — Import a SQL file into the database.
wp db import backup.sqlwp db optimize — Optimize all database tables.
wp db optimizewp db repair — Repair all database tables.
wp db repairwp db size — Show the total database size.
wp db sizewp db size --tables — Show the size of each individual table.
wp db size --tableswp 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 cliwp db check — Check all database tables for errors.
wp db checkwp db tables — List all tables in the WordPress database.
wp db tableswp db reset --yes — Drop all tables and recreate them from the schema. Destroys all data.
wp db reset --yesSearch & 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-runwp search-replace '<old>' '<new>' <table> — Limit the search-replace to specific tables.
wp search-replace 'http://old.com' 'https://new.com' wp_posts wp_postmetawp search-replace '<old>' '<new>' --precise — Use precise mode for more accurate serialized data handling.
wp search-replace 'old-domain.com' 'new-domain.com' --precisewp 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-tableswp 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.sqlCache & Transients
wp cache flush — Flush the WordPress object cache.
wp cache flushwp transient delete --all — Delete all transients from the database.
wp transient delete --allwp transient delete --expired — Delete only expired transients.
wp transient delete --expiredwp transient get <key> — Get the value of a specific transient.
wp transient get my_cached_datawp rewrite flush — Flush and regenerate rewrite rules (fixes permalink issues).
wp rewrite flushwp 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 --yeswp media regenerate --only-missing — Only regenerate missing image sizes (faster than full regeneration).
wp media regenerate --only-missingwp 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-sizeMaintenance & Multisite
wp cron event list — List all scheduled cron events with their next run time.
wp cron event listwp cron event run --all — Run all pending cron events immediately.
wp cron event run --allwp cron event run <hook> — Run a specific cron event by its hook name.
wp cron event run wp_scheduled_auto_draft_deletewp cron test — Test if the WP-Cron spawning system is working correctly.
wp cron testwp maintenance-mode activate — Enable maintenance mode (shows maintenance page to visitors).
wp maintenance-mode activatewp maintenance-mode deactivate — Disable maintenance mode.
wp maintenance-mode deactivatewp site list — List all sites in a WordPress Multisite network.
wp site listwp --url=<site_url> <command> — Run a WP-CLI command against a specific site in a Multisite network.
wp --url=subsite.example.com plugin listScaffolding & Export
wp scaffold plugin <slug> — Generate boilerplate files for a new plugin.
wp scaffold plugin my-custom-pluginwp scaffold child-theme <slug> --parent_theme=<parent> — Generate a child theme.
wp scaffold child-theme my-child --parent_theme=twentytwentyfourwp scaffold post-type <slug> --plugin=<plugin> — Generate code for a custom post type.
wp scaffold post-type product --plugin=my-custom-plugin --label=Productwp scaffold taxonomy <slug> --post_types=<types> — Generate code for a custom taxonomy.
wp scaffold taxonomy genre --post_types=book --plugin=my-custom-pluginwp 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=createOutput Formats & Global Flags
wp <command> --format=table — Output as an ASCII table (default format).
wp plugin list --format=tablewp <command> --format=json — Output as a JSON array.
wp plugin list --format=jsonwp <command> --format=csv — Output as comma-separated values.
wp user list --format=csvwp <command> --format=ids — Output only the IDs, space-separated. Useful for piping.
wp post list --post_type=revision --format=ids | xargs wp post deletewp <command> --fields=<field1>,<field2> — Limit output to specific columns.
wp plugin list --fields=name,status,versionwp <command> --path=<path> — Run WP-CLI against a WordPress installation at a specific path.
wp core version --path=/var/www/htmlwp <command> --ssh=<host> — Run WP-CLI on a remote server via SSH.
wp plugin list --ssh=deploy@server.example.com:/var/www/htmlwp <command> --skip-plugins — Run without loading plugins. Useful when a plugin causes fatal errors.
wp option get siteurl --skip-pluginswp <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
- WP-CLI Handbook – official documentation, guides and command reference
- developer.wordpress.org/cli – full command reference on the WordPress Developer site
- wp-cli.org – the project home page