Skip to main content

wp transient set

Overview

Store a value in the WordPress transient cache with an optional expiration time. Use this to warm up caches, inject test data, override stale API responses during debugging, or pre-populate a plugin's cached data.

Syntax

wp transient set <key> <value> [<expiration>] [--network]

Options

FlagDescription
KEYTransient name
VALUEValue to store (string)
EXPIRATIONOptional TTL in seconds (0 = no expiry)
--networkSet as a network transient

Basic Usage

Set a transient with 1-hour TTL

wp transient set my_api_cache '{"rate":1.23}' 3600

Output:

Success: Transient added.

Set with no expiration

wp transient set my_permanent_flag "true" 0

Verify it was set

wp transient get my_api_cache

Output:

{"rate":1.23}

Real-World Scenarios

Warm up a plugin's API cache for testing

wp transient set plugin_exchange_rate '{"USD":1,"EUR":0.92}' 3600

Override a stuck transient in production

wp transient set broken_plugin_settings '{"enabled":false}' 60

Best Practices

  1. Use short TTLs when testing — a 60-second TTL lets you easily rotate between values.
  2. Match the format the plugin expects — if the plugin stores JSON, store JSON; if it stores a serialized array, store that.
  3. Delete rather than set 0 — to truly disable a transient, delete it; setting it to empty may cause unexpected behaviour.

Quick Reference

wp transient set <key> <value> <ttl>      # Set with expiry
wp transient set <key> <value> 0 # Set permanently
wp transient set <key> <value> 3600 --network # Network transient

Next Steps