tips
78 tips WP-CLI
One command, setting or habit at a time about WP-CLI: what it does, the line to copy and a caveat or two.
WP-CLI 78
-
Lists the widgets placed in one sidebar, with their ID and position.
wp widget list <sidebar-id> -
Lists the registered sidebars with their IDs, which you need for other widget commands.
wp sidebar list -
Lists registered taxonomies, optionally only those that belong to one post type.
wp taxonomy list --format=csv -
Lists the users with super admin capabilities on a WordPress multisite install.
wp super-admin list -
Checks for a newer WP-CLI release and updates the phar after you confirm.
wp cli check-update -
Removes every theme except the active one, so old themes stop waiting for updates.
wp theme delete --all -
Shows the registered image sizes with width, height and crop, so you see what each upload costs.
wp media image-size -
Starts a quick local web server for a WordPress folder without Apache or nginx.
wp server --host=127.0.0.1 --port=8080 -
Approves all pending comments at once after you have checked the list.
wp comment list --status=hold --fields=comment_ID,comment_author,comment_content -
Runs the database upgrade step after new core files, with a dry run to check first.
wp core update-db --dry-run -
Opens an interactive MySQL client already logged in to the site's database.
wp db cli -
Creates a classic menu, adds links and assigns it to a theme location by script.
wp menu create "Main menu" -
Adds a category or tag to a post from the terminal and keeps the terms it has.
wp post term add 123 post_tag docker -
Publishes or drafts a post whose content comes from an HTML file on disk.
wp post create ./draft.html --post_title='Release notes' --post_status=draft --porcelain -
Prints the WordPress version plus database revision, TinyMCE version and package language.
wp core version --extra -
Checks whether one plugin is active and answers with exit code 0 or 1.
if wp plugin is-active woocommerce; then -
Gives a user one new role and removes the roles the account had before.
wp user set-role anna author -
Returns success when WordPress is installed, so a deploy script can branch on it.
if ! wp core is-installed 2>/dev/null; then -
Creates the same WXR file as Tools > Export, filtered by post type or date.
wp export --post_type=page --dir=exports -
Restores a database dump without typing the database user, password or host.
wp db import backup.sql -
Downloads a clean WordPress core in the language you want, without bundled themes and plugins.
wp core download --skip-content --locale=nl_NL -
Imports an export file from the terminal and creates or maps the post authors.
wp import site.wordpress.2026-11-30.000.xml --authors=create -
Prints the capabilities of a role so you can see what editors or shop managers may do.
wp cap list editor | sort -
Lists the terms of a taxonomy with ID, slug and how many posts use each one.
wp term list post_tag --fields=term_id,name,slug,count -
Generates wp-config.php with fresh salts while the password never appears on the command line.
wp config create --dbname=example_wp --dbuser=example --prompt=dbpass -
Lists every column of a table with its type, key and default value.
wp db columns wp_postmeta -
Lists every registered post type, including the hidden ones plugins add.
wp post-type list --fields=name,label,public,hierarchical -
Changes the permalink structure, and optionally the category and tag base, in one command.
wp rewrite structure '/%postname%/' -
Scans a plugin or theme for translatable strings and writes a POT file.
wp i18n make-pot . languages/my-plugin.pot -
Creates any number of placeholder posts or pages to test a theme or a query.
wp post generate --count=50 -
Makes a copy of the database with a new domain in it and leaves the live tables alone.
wp search-replace 'https://old.example.com' 'https://new.example.com' --export=moved.sql -
Runs a SQL query against the WordPress database without needing the database password.
wp db query 'SELECT option_value FROM wp_options WHERE option_name="home"' --skip-column-names -
Searches every WordPress table for a string or regex and shows the table, column and row.
wp db search example.com -
Defragments the WordPress database tables after a big cleanup using the credentials in wp-config.
wp db optimize -
Gives a remote WordPress site a short name so wp commands run over ssh as wp @prod.
@prod: -
Switches off all WordPress plugins at once so you can find which one breaks the site.
wp plugin list --status=active --field=name > active-plugins.txt -
Runs a PHP script file with WordPress fully loaded, passing extra arguments in $args.
$ids = get_posts( array( 'post_status' => 'draft', 'fields' => 'ids', 'numberposts' => -1 ) ); -
Prints the WordPress rewrite rules and lets you see which one matches a given URL.
wp rewrite list --format=csv -
Prints a single nested value from a WordPress option without dumping the whole array.
wp option pluck my_plugin_settings api timeout -
Shows the PHP binary, php.ini, memory limit and config files that WP-CLI is using.
wp cli info -
Lists constants and variables from wp-config.php, optionally filtered by name.
wp config list WP_DEBUG -
Lists every role on a WordPress site, including any that plugins added.
wp role list -
Prints all custom fields (post meta) of a single post, optionally filtered by key.
wp post meta list 123 -
Adds images from a folder or URL to the WordPress media library without the browser.
wp media import /tmp/photos/*.jpg --post_id=123 --alt="Leiden in the snow" -
Puts an older version of a WordPress plugin back after an update breaks something.
wp plugin install my-plugin --version=2.4.1 --force -
Creates a WordPress child theme so your theme changes survive updates of the parent theme.
wp scaffold child-theme my-child --parent_theme=twentytwentyone --theme_name="My child" --activate -
Deletes every comment in the WordPress spam folder permanently with one WP-CLI command.
wp comment delete $(wp comment list --status=spam --format=ids) --force -
Switches WordPress plugin auto-updates on or off from the command line, per plugin or all.
wp plugin auto-updates status --all -
Turns WordPress maintenance mode on and off from the command line.
wp maintenance-mode activate -
Lists the available WordPress cron schedules, such as hourly and daily, with their intervals in seconds.
wp cron schedule list -
Lists, installs and updates the core language packs of a WordPress site from the command line.
wp language core install nl_NL -
Lists draft posts from the command line with the fields and output format you choose.
wp post list --post_status=draft -
Starts an interactive PHP console with WordPress loaded, to try functions and inspect data.
wp shell -
Runs a table check on the whole WordPress database using the credentials from wp-config.php.
wp db check -
Counts the replacements WP-CLI would make in your WordPress database without changing anything.
wp search-replace 'http://old.example' 'https://new.example' --dry-run -
Moving a WordPress site to a new domain means changing the old address everywhere in the database, and a wrong replace is painful to undo. WP-CLI lets you see the…
wp search-replace 'http://old.example' 'https://www.example.nl' --dry-run -
Shows how many bytes of WordPress options load on every page request, and which ones are biggest.
wp option list --autoload=on --format=total_bytes -
Lets WP-CLI run on a crashing WordPress site by not loading plugins or themes, so you can fix it.
wp plugin list --skip-plugins --skip-themes -
Creates only the missing image sizes after a theme change instead of redoing every thumbnail.
wp media regenerate --only-missing --yes -
Removes expired cached values from the WordPress database without touching the ones still in use.
wp transient delete --expired -
Sets a constant in wp-config.php as a real true or false value, without hand-editing the file.
wp config set WP_DEBUG true --raw -
Checks the files of every installed plugin against WordPress.org and lists any that do not match.
wp plugin verify-checksums --all -
Compares your WordPress core files with the official list and reports anything changed or unexpected.
wp core verify-checksums -
Writes a compressed copy of your WordPress database without leaving an uncompressed dump on disk.
wp db export - | gzip > backup-$(date +%F).sql.gz -
Scans a Redis instance and reports the biggest keys per type without blocking the server.
redis-cli --bigkeys -i 0.1 -
Shows live Redis commands for a moment while keeping the load on a busy server small.
redis-cli monitor | head -n 20 -
Shows which object cache backend is active and clears it when stale values appear.
wp cache type -
Executes a snippet of PHP with WordPress loaded, without writing a plugin or a template.
wp eval 'echo get_option( "blogname" ), PHP_EOL;' -
Lists the size of every table in the WordPress database to find what makes it grow.
wp db size --tables --orderby=size --order=desc -
Lists the WordPress core updates that are available, split into major and minor versions.
wp core check-update -
Selects which site of a multisite network a WP-CLI command should run on.
wp plugin list --status=active --url=https://shop.example.com -
Prints the sites of a multisite network, either as a table or as plain URLs for scripts.
wp site list --fields=blog_id,url,registered --format=table -
Shows every scheduled WordPress task with its next run time and repeat interval.
wp cron event list -
Rebuilds the permalink rules, and the .htaccess file with --hard, to cure 404 errors on posts.
wp rewrite flush --hard -
Reads the stored site address and home address to find the cause of redirect loops.
wp option get siteurl -
Sets a new random password for a user without sending an email and prints it in the terminal.
wp user reset-password admin --skip-email --show-password -
Adds a user with a chosen role from the terminal and prints only the new ID.
wp user create anna [email protected] --role=editor --porcelain -
Lists only the plugins that have a newer version available, with installed and offered versions.
wp plugin list --update=available --fields=name,version,update_version
Nothing in this filter yet.