WordPress at a glance
Home Handbook WP-CLI Commands

wp transient

Adds, gets, and deletes entries in the WordPress Transient Cache.

By default, the transient cache uses the WordPress database to persist values between requests. On a single site installation, values are stored in the wp_options table. On a multisite installation, values are stored in the wp_options or the wp_sitemeta table, depending on use of the --network flag.

When a persistent object cache drop-in is installed (e.g. Redis or Memcached), the transient cache skips the database and simply wraps the WP Object Cache.

Commands Description
Gets a transient value.
Sets a transient value.
Deletes a transient value.
Determines the type of transients implementation.
Lists transients and their values.

Examples

# Set transient.
$ wp transient set sample_key "test data" 3600
Success: Transient added.

# Get transient.
$ wp transient get sample_key
test data

# Delete transient.
$ wp transient delete sample_key
Success: Transient deleted.

# Delete expired transients.
$ wp transient delete --expired
Success: 12 expired transients deleted from the database.

# Delete all transients.
$ wp transient delete --all
Success: 14 transients deleted from the database.

Source code of the commands


wp transient get

Gets a transient value.

For a more complete explanation of the transient cache, including the network|site cache, please see docs for wp transient.

Usage

wp transient get {key} [--format={format}] [--network]

You can specify global options and the following:

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

Render output in a particular format.
Default: table
Can be:

  • table
  • csv
  • json
  • yaml
[--network]
Get the value of a network|site transient. On single site, this is is a specially-named cache key. On multisite, this is a global cache (instead of local to the site).

Examples

$ wp transient get sample_key
test data
$ wp transient get random_key
Warning: Transient with key "random_key" is not set.
menu

wp transient set

Sets a transient value.

<expiration> is the time until expiration, in seconds.

For a more complete explanation of the transient cache, including the network|site cache, please see docs for wp transient.

Usage

wp transient set {key} {value} [{expiration}] [--network]

You can specify global options and the following:

{key}
Key for the transient.
{value}
Value to be set for the transient.
[{expiration}]
Time until expiration, in seconds.
[--network]
Set the value of a network|site transient. On single site, this is is a specially-named cache key. On multisite, this is a global cache (instead of local to the site).

Examples

$ wp transient set sample_key "test data" 3600
Success: Transient added.
menu

wp transient delete

Deletes a transient value.

For a more complete explanation of the transient cache, including the network|site cache, please see docs for wp transient.

Usage

wp transient delete [{key}] [--network] [--all] [--expired]

You can specify global options and the following:

[{key}]
Key for the transient.
[--network]
Delete the value of a network|site transient. On single site, this is is a specially-named cache key. On multisite, this is a global cache (instead of local to the site).
[--all]
Delete all transients.
[--expired]
Delete all expired transients.

Examples

# Delete transient.
$ wp transient delete sample_key
Success: Transient deleted.
# Delete expired transients.
$ wp transient delete --expired
Success: 12 expired transients deleted from the database.
# Delete expired site transients.
$ wp transient delete --expired --network
Success: 1 expired transient deleted from the database.
# Delete all transients.
$ wp transient delete --all
Success: 14 transients deleted from the database.
# Delete all site transients.
$ wp transient delete --all --network
Success: 2 transients deleted from the database.
# Delete all transients in a multsite.
$ wp transient delete --all --network && wp site list --field=url | xargs -n1 -I % wp --url=% transient delete --all
menu

wp transient type

Determines the type of transients implementation.

Indicates whether the transients API is using an object cache or the database.

For a more complete explanation of the transient cache, including the network|site cache, please see docs for wp transient.

Usage

wp transient type 

Examples

$ wp transient type
Transients are saved to the database.

wp transient list

Lists transients and their values.

Usage

wp transient list [--search={pattern}] [--exclude={pattern}] [--network] [--unserialize] [--human-readable] [--fields={fields}] [--format={format}]

You can specify global options and the following:

[--search={pattern}]
Use wildcards ( * and ? ) to match transient name.
[--exclude={pattern}]
Pattern to exclude. Use wildcards ( * and ? ) to match transient name.
[--network]
Get the values of network|site transients. On single site, this is a specially-named cache key. On multisite, this is a global cache (instead of local to the site).
[--unserialize]
Unserialize transient values in output.
[--human-readable]
Human-readable output for expirations.
[--fields={fields}]
Limit the output to specific object fields.
[--format={format}]

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

  • table
  • json
  • csv
  • count
  • yaml

Available fields

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

  • name
  • value
  • expiration

Examples

# List all transients
$ wp transient list
 +------+-------+---------------+
 | name | value | expiration    |
 +------+-------+---------------+
 | foo  | bar   | 39 mins       |
 | foo2 | bar2  | no expiration |
 | foo3 | bar2  | expired       |
 | foo4 | bar4  | 4 hours       |
 +------+-------+---------------+