WordPress at a glance
Home Handbook WP-CLI Commands

wp option

Retrieves and sets site options, including plugin and WordPress settings.

See the Plugin Settings API and the Theme Options for more information on adding customized options.

Commands Description
Gets the value for an option.
Adds a new option value.
Lists options and their values.
Updates an option value.
Deletes an option.
Gets a nested value from an option.
Updates a nested value in an option.

Examples

# Get site URL.
$ wp option get siteurl
http://example.com

# Add option.
$ wp option add my_option foobar
Success: Added 'my_option' option.

# Update option.
$ wp option update my_option '{"foo": "bar"}' --format=json
Success: Updated 'my_option' option.

# Delete option.
$ wp option delete my_option
Success: Deleted 'my_option' option.

Source code of the commands


wp option get

Gets the value for an option.

Usage

wp option get {key} [--format={format}]

You can specify global options and the following:

{key}
Key for the option.
[--format={format}]

Get value in a particular format.
Default: var_export
Can be:

  • var_export
  • json
  • yaml

Examples

# Get option.
$ wp option get home
http://example.com
# Get blog description.
$ wp option get blogdescription
A random blog description
# Get blog name
$ wp option get blogname
A random blog name
# Get admin email.
$ wp option get admin_email
someone@example.com
# Get option in JSON format.
$ wp option get active_plugins --format=json
{"0":"dynamically-dynamic-sidebar\/dynamically-dynamic-sidebar.php","1":"monster-widget\/monster-widget.php","2":"show-current-template\/show-current-template.php","3":"theme-check\/theme-check.php","5":"wordpress-importer\/wordpress-importer.php"}
menu

wp option add

Adds a new option value.

Errors if the option already exists.

Usage

wp option add {key} [{value}] [--format={format}] [--autoload={autoload}]

You can specify global options and the following:

{key}
The name of the option to add.
[{value}]
The value of the option to add. If ommited, the value is read from STDIN.
[--format={format}]

The serialization format for the value.
Default: plaintext
Can be:

  • plaintext
  • json
[--autoload={autoload}]

Should this option be automatically loaded.

Can be:

  • 'yes'
  • 'no'

Examples

# Create an option by reading a JSON file.
$ wp option add my_option --format=json < config.json
Success: Added 'my_option' option.
menu

wp option list

Lists options and their values.

Usage

wp option list [--search={pattern}] [--exclude={pattern}] [--autoload={value}] [--transients] [--unserialize] [--field={field}] [--fields={fields}] [--format={format}] [--orderby={fields}] [--order={order}]

You can specify global options and the following:

[--search={pattern}]
Use wildcards ( * and ? ) to match option name.
[--exclude={pattern}]
Pattern to exclude. Use wildcards ( * and ? ) to match option name.
[--autoload={value}]
Match only autoload options when value is on, and only not-autoload option when off.
[--transients]
List only transients. Use --no-transients to ignore all transients.
[--unserialize]
Unserialize option values in output.
[--field={field}]
Prints the value of a single field.
[--fields={fields}]
Limit the output to specific object fields.
[--format={format}]

The serialization format for the value. total_bytes displays the total size of matching options in bytes.
Default: table
Can be:

  • table
  • json
  • csv
  • count
  • yaml
  • total_bytes
[--orderby={fields}]

Set orderby which field.
Default: option_id
Can be:

  • option_id
  • option_name
  • option_value
[--order={order}]

Set ascending or descending order.
Default: asc
Can be:

  • asc
  • desc

Available fields

This field will be displayed by default for each matching option:

  • option_name
  • option_value

These fields are optionally available:

  • autoload
  • size_bytes

Examples

# Get the total size of all autoload options.
$ wp option list --autoload=on --format=total_bytes
33198
# Find biggest transients.
$ wp option list --search="*_transient_*" --fields=option_name,size_bytes | sort -n -k 2 | tail
option_name size_bytes
_site_transient_timeout_theme_roots 10
_site_transient_theme_roots 76
_site_transient_update_themes   181
_site_transient_update_core 808
_site_transient_update_plugins  6645
# List all options beginning with "i2f_".
$ wp option list --search="i2f_*"
+-------------+--------------+
| option_name | option_value |
+-------------+--------------+
| i2f_version | 0.1.0        |
+-------------+--------------+
# Delete all options beginning with "theme_mods_".
$ wp option list --search="theme_mods_*" --field=option_name | xargs -I % wp option delete %
Success: Deleted 'theme_mods_twentysixteen' option.
Success: Deleted 'theme_mods_twentyfifteen' option.
Success: Deleted 'theme_mods_twentyfourteen' option.
menu

wp option update

Updates an option value.

Usage

wp option update {key} [{value}] [--autoload={autoload}] [--format={format}]

You can specify global options and the following:

{key}
The name of the option to update.
[{value}]
The new value. If ommited, the value is read from STDIN.
[--autoload={autoload}]

Requires WP 4.2. Should this option be automatically loaded.

Can be:

  • 'yes'
  • 'no'
[--format={format}]

The serialization format for the value.
Default: plaintext
Can be:

  • plaintext
  • json

Examples

# Update an option by reading from a file.
$ wp option update my_option < value.txt
Success: Updated 'my_option' option.
# Update one option on multiple sites using xargs.
$ wp site list --field=url | xargs -n1 -I {} sh -c 'wp --url={} option update my_option my_value'
Success: Updated 'my_option' option.
Success: Updated 'my_option' option.
# Update site blog name.
$ wp option update blogname "Random blog name"
Success: Updated 'blogname' option.
# Update site blog description.
$ wp option update blogdescription "Some random blog description"
Success: Updated 'blogdescription' option.
# Update admin email address.
$ wp option update admin_email someone@example.com
Success: Updated 'admin_email' option.
# Set the default role.
$ wp option update default_role author
Success: Updated 'default_role' option.
# Set the timezone string.
$ wp option update timezone_string "America/New_York"
Success: Updated 'timezone_string' option.
menu

wp option delete

Deletes an option.

Usage

wp option delete {key}

You can specify global options and the following:

{key}
Key for the option.

Examples

# Delete an option.
$ wp option delete my_option
Success: Deleted 'my_option' option.

wp option pluck

Gets a nested value from an option.

Usage

wp option pluck {key} {key-path}... [--format={format}]

You can specify global options and the following:

{key}
The option name.
{key-path}...
The name(s) of the keys within the value to locate the value to pluck.
[--format={format}]

The output format of the value.
Default: plaintext
Can be:

  • plaintext
  • json
  • yaml

wp option patch

Updates a nested value in an option.

Usage

wp option patch {action} {key} {key-path}... [{value}] [--format={format}]

You can specify global options and the following:

{action}

Patch action to perform.

Can be:

  • insert
  • update
  • delete
{key}
The option name.
{key-path}...
The name(s) of the keys within the value to locate the value to patch.
[{value}]
The new value. If omitted, the value is read from STDIN.
[--format={format}]

The serialization format for the value.
Default: plaintext
Can be:

  • plaintext
  • json