Argument Syntax


目录

WP-CLI commands use a standardized syntax to describe their arguments and options. Understanding this syntax will help you use commands correctly and avoid confusion.

Syntax Conventions

The command synopsis uses specific formatting to indicate whether arguments are required or optional, and what type of values they accept.

Required Arguments

Arguments without square brackets are required and must be provided:

Optional Arguments

Arguments enclosed in square brackets [ ] are optional:

Boolean Flags

Boolean flags are switches that enable or disable a feature:

Associative Arguments

Some commands accept arbitrary key-value pairs:

Repeatable Arguments

Arguments that can be provided multiple times:

Variadic Arguments

Arguments that accept multiple values:

Value Placeholders

The text inside angle brackets describes what kind of value is expected:

Common Patterns

Required Database Connection

Many commands require database connection details:

--dbname=<dbname> --dbuser=<dbuser> [--dbpass=<dbpass>] [--dbhost=<dbhost>]

Format Options

Commands that output data often accept a format option:

[--format=<format>]

Common formats include: table, csv, json, yaml, count

Fields and Filtering

Commands that work with multiple fields:

[--fields=<fields>] [--field=<field>]

Examples

Here are practical examples showing different syntax types:

# Required arguments (no brackets)
wp config create --dbname=mydb --dbuser=root

# Optional arguments with defaults
wp config create --dbname=mydb --dbuser=root --dbhost=localhost

# Boolean flags
wp plugin install hello-dolly --activate --force

# Negated boolean flags
wp plugin list --no-color

# Associative arguments
wp cron event schedule my_hook --foo=bar --baz=qux

# Multiple values
wp plugin install plugin1 plugin2 plugin3

# Optional fields with specific format options
wp post list --format=json --fields=ID,post_title,post_date

Tips


版本号 #4
由 cocobook-sync 创建于 2026-10-28 11:01:24 UTC
由 cocobook-sync 更新于 2026-10-29 01:42:31 UTC