wp cache get
Overview
Retrieve a single cached value by its key and group. Use this to inspect what WordPress has stored in memory for a specific cache entry — invaluable for debugging stale data, plugin caching behavior, and verifying cache warming.
What It Does
wp cache get calls wp_cache_get() and outputs the stored value. If the key doesn't exist, it returns a "no cache key found" error.
Syntax
wp cache get <key> [<group>]
Arguments
| Argument | Description |
|---|---|
KEY | The cache key to retrieve |
GROUP | Cache group (namespace) — optional, defaults to default |
Basic Usage
Get a cached option value
wp cache get alloptions options
Get from the default group
wp cache get my_custom_cache_key
Get a post cache entry
wp cache get 42 posts
Common Cache Groups
| Group | Holds |
|---|---|
options | WordPress options (alloptions, etc.) |
posts | Post objects by ID |
users | User objects |
terms | Term objects |
transient | Transient values |
site-transient | Network-wide transients |
counts | Comment/post counts |
Real-World Scenarios
Scenario 1: Inspect if a plugin's cache entry exists
wp cache get "woocommerce_product_count" "counts"
Scenario 2: Debug stale options
# Check if alloptions is cached
wp cache get alloptions options
# If value shows old URL → cache is stale → flush
wp cache flush
Scenario 3: Verify a custom cache key after setting
wp cache set my_key "hello world" default 3600
wp cache get my_key default
# Output: hello world
Troubleshooting
| Problem | Cause | Fix |
|---|---|---|
Error: Object cache returned a non-boolean value | Cache miss | Key doesn't exist yet — check if it was set |
| Output is empty | Cache expired or no persistent backend | Check wp cache type |
| Returns stale data | Cache not flushed after update | Run wp cache flush |
Quick Reference
wp cache get <key> # Default group
wp cache get <key> <group> # Specific group
wp cache get alloptions options # Inspect options cache
Next Steps
wp cache set— write a value to the cache.wp cache delete— remove a specific cache key.wp cache flush— clear everything.