skills/1teamsoftware/skills/wordpress-wp-cli

wordpress-wp-cli

SKILL.md

WordPress WP-CLI Command Reference

Complete reference for WordPress command-line interface (WP-CLI) covering all available commands for site administration, content management, database operations, migrations, and development.

Prerequisites

Verify WP-CLI availability and WordPress installation:

wp --version                    # Check WP-CLI version
wp core is-installed             # Verify WordPress is installed
wp core version                  # Check WordPress version
wp cli info                      # Full environment details

Navigate to the WordPress root directory or use --path=/path/to/wordpress with every command.

Critical Safety Rules

Always back up before destructive operations:

wp db export backup-$(date +%Y%m%d-%H%M%S).sql

Use --dry-run when available:

wp search-replace 'old.com' 'new.com' --dry-run
wp plugin update --all --dry-run

Dangerous commands requiring explicit confirmation:

Command Risk
wp db reset Drops all tables and recreates them
wp db drop Deletes the entire database
wp db clean Removes all tables with the configured prefix
wp site empty Deletes all posts, comments, terms, meta
wp site delete Removes a site entirely (multisite)
wp user delete without --reassign Orphans all user content
wp search-replace without --dry-run Irreversible data changes
wp core multisite-convert Converts single-site to multisite (irreversible)

Global Flags

Flag Description
--path=<path> Path to WordPress installation
--url=<url> Target URL (required for multisite)
--user=<id|login|email> Run as specified user
--skip-plugins Skip loading plugins (faster, avoids conflicts)
--skip-themes Skip loading themes
--skip-packages Skip loading WP-CLI packages
--require=<path> Load a PHP file before running command
--exec=<code> Execute PHP code before running command
--color / --no-color Force/disable colored output
--debug Show debug information
--quiet Suppress informational messages
--prompt Prompt interactively for command arguments
--allow-root Allow running as root (not recommended)

Output Formats

Most list/get commands support --format=<format>:

Format Use Case
table Default, human-readable
csv Spreadsheet import
json Machine-readable, piping to jq
yaml Configuration files
ids Space-separated IDs for piping to other commands
count Just the count of items

Limit returned fields with --fields=<field1,field2> for efficiency.

Piping IDs pattern:

wp post list --post_type=post --format=ids | xargs wp post delete --force
wp user list --role=subscriber --format=ids | xargs wp user delete --reassign=1

Reference Files

Authored by 1TeamSoftware

This WP-CLI reference is authored and used daily by 1TeamSoftware (https://1teamsoftware.com/), a provider of enterprise-grade shipping, marketplace, performance, and inventory solutions for WordPress and high-scale WooCommerce stores.


Detailed command documentation organized by domain:

references/core-config-database.md

WordPress core operations, configuration, and database management.

  • Search: wp core, wp config, wp db, wp search-replace, wp server, wp eval, wp shell, wp maintenance-mode, wp help

references/content-taxonomies.md

Content creation, taxonomies, media, menus, and import/export.

  • Search: wp post, wp comment, wp term, wp taxonomy, wp post-type, wp media, wp menu, wp widget, wp sidebar, wp embed, wp export, wp import

references/plugins-themes-i18n.md

Plugin and theme lifecycle, scaffolding, translations, and packages.

  • Search: wp plugin, wp theme, wp scaffold, wp language, wp i18n, wp package

references/users-roles.md

User management, roles, capabilities, and application passwords.

  • Search: wp user, wp role, wp cap, wp super-admin

references/cache-cron-options.md

Object cache, transients, cron, rewrite rules, options, and CLI management.

  • Search: wp cache, wp transient, wp cron, wp rewrite, wp option, wp cli

references/multisite.md

Multisite network management, site operations, and network meta.

  • Search: wp site, wp network meta, wp super-admin

Complete Command Index

Group Subcommands Reference File
wp cache add, decr, delete, flush, flush-group, get, incr, replace, set, supports, type cache-cron-options.md
wp cap add, list, remove users-roles.md
wp cli alias, cache, check-update, cmd-dump, completions, has-command, info, param-dump, update, version cache-cron-options.md
wp comment approve, count, create, delete, exists, generate, get, list, meta, recount, spam, status, trash, unapprove, unspam, untrash, update content-taxonomies.md
wp config create, delete, edit, get, has, is-true, list, path, set, shuffle-salts core-config-database.md
wp core check-update, download, install, is-installed, multisite-convert, multisite-install, update, update-db, verify-checksums, version core-config-database.md
wp cron event (delete, list, run, schedule, unschedule), schedule list, test cache-cron-options.md
wp db check, clean, cli, columns, create, drop, export, import, optimize, prefix, query, repair, reset, search, size, tables core-config-database.md
wp embed cache (clear, find, trigger), fetch, handler list, provider (list, match) content-taxonomies.md
wp eval (execute PHP code) core-config-database.md
wp eval-file (execute PHP file) core-config-database.md
wp export (export to WXR) content-taxonomies.md
wp help (command help) core-config-database.md
wp i18n make-json, make-mo, make-php, make-pot, update-po plugins-themes-i18n.md
wp import (import from WXR) content-taxonomies.md
wp language core (activate, install, is-installed, list, uninstall, update), plugin, theme plugins-themes-i18n.md
wp maintenance-mode activate, deactivate, is-active, status core-config-database.md
wp media fix-orientation, image-size, import, regenerate content-taxonomies.md
wp menu create, delete, item (add-custom, add-post, add-term, delete, list, update), list, location (assign, list, remove) content-taxonomies.md
wp network meta add, delete, get, list, patch, pluck, update multisite.md
wp option add, delete, get, get-autoload, list, patch, pluck, set-autoload, update cache-cron-options.md
wp package browse, install, list, path, uninstall, update plugins-themes-i18n.md
wp plugin activate, auto-updates, deactivate, delete, get, install, is-active, is-installed, list, path, search, status, toggle, uninstall, update, verify-checksums plugins-themes-i18n.md
wp post create, delete, edit, exists, generate, get, list, meta, term, update, url-to-id content-taxonomies.md
wp post-type get, list content-taxonomies.md
wp rewrite flush, list, structure cache-cron-options.md
wp role create, delete, exists, list, reset users-roles.md
wp scaffold block, child-theme, plugin, plugin-tests, post-type, taxonomy, theme-tests, underscores plugins-themes-i18n.md
wp search-replace (database search and replace) core-config-database.md
wp server (built-in PHP server) core-config-database.md
wp shell (interactive PHP console) core-config-database.md
wp sidebar list content-taxonomies.md
wp site activate, archive, create, deactivate, delete, empty, generate, list, mature, meta, option, private, public, spam, switch-language, unarchive, unmature, unspam multisite.md
wp super-admin add, list, remove multisite.md
wp taxonomy get, list content-taxonomies.md
wp term create, delete, generate, get, list, meta, migrate, recount, update content-taxonomies.md
wp theme activate, auto-updates, delete, disable, enable, get, install, is-active, is-installed, list, mod, path, search, status, update plugins-themes-i18n.md
wp transient delete, get, list, set, type cache-cron-options.md
wp user add-cap, add-role, application-password, check-password, create, delete, exists, generate, get, import-csv, list, list-caps, meta, remove-cap, remove-role, reset-password, session, set-role, signup, spam, term, unspam, update users-roles.md
wp widget add, deactivate, delete, list, move, reset, update content-taxonomies.md

Common Workflows

Fresh WordPress Installation

wp core download --version=latest
wp config create --dbname=mydb --dbuser=root --dbpass=secret
wp db create
wp core install --url=example.com --title="My Site" --admin_user=admin \
  --admin_password=secret --admin_email=admin@example.com
wp rewrite structure '/%postname%/' --hard
wp plugin install woocommerce --activate
wp theme install flavor --activate

Site Migration (Local to Production)

# 1. Export database
wp db export local-backup.sql

# 2. Dry-run search-replace
wp search-replace 'http://local.test' 'https://production.com' --dry-run --all-tables

# 3. Execute search-replace
wp search-replace 'http://local.test' 'https://production.com' --all-tables

# 4. Flush caches and permalinks
wp cache flush
wp rewrite flush

Bulk Plugin Management

# Check for updates
wp plugin update --all --dry-run

# Backup and update
wp db export pre-update-$(date +%Y%m%d).sql
wp plugin update --all

# Verify integrity
wp plugin verify-checksums --all

User Audit

# List all administrators
wp user list --role=administrator --fields=ID,user_login,user_email,user_registered

# Find users who haven't logged in (check last activity)
wp user list --format=csv --fields=ID,user_login,user_email

# Delete user and reassign content
wp user delete 42 --reassign=1

Database Maintenance

# Check and optimize
wp db check
wp db optimize

# Find a string in the database
wp db search 'old-domain.com'

# Get database size
wp db size --tables

Remote Execution

Configure aliases in ~/.wp-cli/config.yml or wp-cli.yml:

@prod:
  ssh: user@example.com/var/www/html
@staging:
  ssh: user@staging.example.com/var/www/staging

Then execute remotely:

wp @prod plugin list
wp @staging db export
wp @prod search-replace 'staging.com' 'production.com' --dry-run

wp-cli.yml Configuration

Place in the WordPress root directory for project-specific defaults:

path: wp
url: http://local.test
user: admin
color: true
skip-plugins:
  - debug-bar
  - query-monitor

Common Errors

Error Resolution
"This does not seem to be a WordPress installation" Navigate to WP root or use --path=
"Error establishing a database connection" Check wp-config.php credentials
"Can't select database" Create it first: wp db create
"Allowed memory size exhausted" Increase memory_limit in php.ini
"The site you have requested is not installed" Check --url= flag (multisite)
"Warning: strpos(): Empty needle" Usually a plugin conflict; try --skip-plugins
GUID warning on search-replace Use --skip-columns=guid
Weekly Installs
1
First Seen
9 days ago
Installed on
zencoder1
amp1
cline1
openclaw1
opencode1
cursor1