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
| Flag | Description |
|---|---|
KEY | Transient name |
VALUE | Value to store (string) |
EXPIRATION | Optional TTL in seconds (0 = no expiry) |
--network | Set 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
- Use short TTLs when testing — a 60-second TTL lets you easily rotate between values.
- Match the format the plugin expects — if the plugin stores JSON, store JSON; if it stores a serialized array, store that.
- 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
wp transient get— verify the value.wp transient delete— remove the transient.