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.

Subcommands

CommandDescription
wp option addAdds a new option value.
wp option deleteDeletes an option.
wp option getGets the value for an option.
wp option get-autoloadGets the ‘autoload’ value for an option.
wp option listLists options and their values.
wp option patchUpdates a nested value in an option.
wp option pluckGets a nested value from an option.
wp option set-autoloadSets the ‘autoload’ value for an option.
wp option updateUpdates an option value.

wp option add

Adds a new option value. Errors if the option already exists.

Synopsis

bash
wp option add <key> [<value>] [--format=<format>] [--autoload=<autoload>]

Options

<key> : The name of the option to add.

[<value>] : The value of the option to add. If omitted, the value is read from STDIN.

[--format=<format>] : The serialization format for the value (plaintext, json).

[--autoload=<autoload>] : Should this option be automatically loaded (on, off, yes, no).

Examples

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

wp option delete

Deletes an option.

Synopsis

bash
wp option delete <key>...

Options

<key>... : Key for the option.

Examples

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

# Delete multiple options.
$ wp option delete option_one option_two option_three
Success: Deleted 'option_one' option.
Success: Deleted 'option_two' option.
Warning: Could not delete 'option_three' option. Does it exist?

wp option get

Gets the value for an option.

Synopsis

bash
wp option get <key> [--format=<format>]

Options

<key> : Key for the option.

[--format=<format>] : Get value in a particular format (var_export, json, yaml).

Examples

bash
# Get option.
$ wp option get home
http://example.com

# Get blog description.
$ wp option get blogdescription
A random blog description

# Get admin email.
$ wp option get admin_email
[email protected]

# 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"}

wp option get-autoload

Gets the ‘autoload’ value for an option.

Synopsis

bash
wp option get-autoload <key>

Options

<key> : The name of the option to get ‘autoload’ of.

Examples

bash
$ wp option get-autoload blogname
yes

wp option list

Lists options and their values.

Synopsis

bash
wp option list [--search=<pattern>] [--exclude=<pattern>] [--autoload=<value>] [--transients] [--unserialize] [--field=<field>] [--fields=<fields>] [--format=<format>] [--orderby=<fields>] [--order=<order>]

Options

[--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 (table, json, csv, count, yaml, total_bytes).

[--orderby=<fields>] : Set orderby which field (option_id, option_name, option_value).

[--order=<order>] : Set ascending or descending order (asc, desc).

Available Fields

Default: option_name, option_value

Optional: autoload, size_bytes

Examples

bash
# 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

# 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.

wp option patch

Updates a nested value in an option.

Synopsis

bash
wp option patch <action> <key> <key-path>... [<value>] [--format=<format>]

Options

<action> : Patch action to perform (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 (plaintext, json).

Examples

bash
# Add 'bar' to the 'foo' key on an option with name 'option_name'
$ wp option patch insert option_name foo bar
Success: Updated 'option_name' option.

# Update the value of 'foo' key to 'new' on an option with name 'option_name'
$ wp option patch update option_name foo new
Success: Updated 'option_name' option.

# Delete the nested key 'bar' under 'foo' key on an option with name 'option_name'.
$ wp option patch delete option_name foo bar
Success: Updated 'option_name' option.

wp option pluck

Gets a nested value from an option.

Synopsis

bash
wp option pluck <key> <key-path>... [--format=<format>]

Options

<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 (plaintext, json, yaml).

wp option set-autoload

Sets the ‘autoload’ value for an option.

Synopsis

bash
wp option set-autoload <key> <autoload>

Options

<key> : The name of the option to set ‘autoload’ for.

<autoload> : Should this option be automatically loaded (on, off, yes, no).

Examples

bash
$ wp option set-autoload abc_options no
Success: Updated autoload value for 'abc_options' option.

wp option update

Updates an option value.

Synopsis

bash
wp option update <key> [<value>] [--autoload=<autoload>] [--format=<format>]

Options

<key> : The name of the option to update.

[<value>] : The new value. If omitted, the value is read from STDIN.

[--autoload=<autoload>] : Requires WP 4.2. Should this option be automatically loaded (on, off, yes, no).

[--format=<format>] : The serialization format for the value (plaintext, json).

Examples

bash
# Update an option by reading from a file.
$ wp option update my_option < value.txt
Success: Updated 'my_option' option.

# Update site blog name.
$ wp option update blogname "Random blog name"
Success: Updated 'blogname' option.

# Update admin email address.
$ wp option update admin_email [email protected]
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.