Explainers · Explainer
What Is a Transient in WordPress? A Plain Explanation

Short answer
A transient is a named piece of data WordPress saves for a limited time, such as a query result or an API reply, so it can reuse the value instead of rebuilding it on every page. WordPress stores it in the wp_options table by default, or in memory when a persistent object cache is active. Each transient has an expiration time in seconds, and code must always be ready to rebuild the value when it is gone.
Key takeaways
- A transient is temporary cached data with an expiration time, stored under a name your code chooses.
- By default transients live in the wp_options table; with Redis or Memcached they live in memory instead.
- Expiration is a maximum age, not a promise: a transient can vanish before its end time.
- Always set an expiration, since a transient with no expiration is autoloaded on every page.
- Transient names must be 172 characters or fewer, or WordPress fails to save them.
- WP-CLI can list, read, and clear transients, including expired ones only.
What is a transient in WordPress?
A transient is a named piece of data WordPress saves for a limited time so it can reuse it without repeating slow work.
WordPress stores transients through the Transients API, which saves a value under a name you choose, plus an end time. A plugin might save the result of a slow database query or the reply from an outside service, then read the saved copy on later visits instead of doing the work again.
Think of it as short-term memory for your site. The value is there when needed, and it can vanish at any time without breaking anything, because the code that saved it can build it again.
How does a transient work?
Your code asks for the saved value first, and it only rebuilds the value when nothing is saved.
The pattern has three steps:
get_transient()asks for the value by name.- If the answer is
false, the code runs the slow query or request and builds a fresh value. set_transient()saves that value with an end time in seconds.
The WordPress Developer Blog shows this pattern with a list of post IDs: the code checks the transient, runs a WP_Query for 25 posts only on a miss, then saves the IDs for a week with WEEK_IN_SECONDS.
The same check-then-build pattern works for API replies, rendered HTML, and any other value that costs time to make.
Where does WordPress store transients?
By default, WordPress stores transients as rows in the wp_options table of its database.
Each transient takes two rows there. WordPress adds the prefix _transient_ to the value row and _transient_timeout_ to the row that holds the end time, as the set_transient() reference shows. On a multisite network, site-wide transients go in the wp_sitemeta table instead, according to the WP-CLI transient docs.
A persistent object cache changes the storage spot. When a drop-in for Redis or Memcached is active, transients skip the database and live in memory instead.
The switch needs no code changes, and reads get faster because memory beats a database query. The Transients API handbook notes that transients should never be assumed to live in the database, since they may not be stored there at all.
What are the three main transient functions?
Three functions cover the whole API: set_transient() saves, get_transient() reads, and delete_transient() removes.
| Function | What it does | What it returns |
|---|---|---|
set_transient( $name, $value, $expiration ) | Saves or updates a value | true on success, false on failure |
get_transient( $name ) | Reads a value by name | The value, or false when missing or expired |
delete_transient( $name ) | Removes a value before it expires | true when deleted, false when not found |
The API dates back to WordPress 2.8.0, when set_transient() was first added, as its reference page records. Multisite adds three matching functions with a site_ prefix: set_site_transient(), get_site_transient(), and delete_site_transient().
Note the strict check: get_transient() returns false for a missing value, so code should test with false === rather than a loose check.
A saved value of 0 or an empty string is still real data, and a loose check would treat it as a miss. The handbook also warns against storing plain boolean values in a transient for the same reason.
How long does a transient last?
A transient lasts until its expiration time at most, but WordPress may drop it sooner.
The expiration you set is a maximum age, not a promised minimum. The WordPress Developer Blog explains that a transient can vanish one second after you set it, for example when an object cache is flushed or the database changes. Your code must always be ready to rebuild the value.
WordPress defines time constants in version 3.5 so you never write raw seconds by hand, as the Transients API handbook records:
| Constant | Seconds | Common use |
|---|---|---|
MINUTE_IN_SECONDS | 60 | Short caches, like a fresh API check |
HOUR_IN_SECONDS | 3,600 | Hourly data, like weather |
DAY_IN_SECONDS | 86,400 | Daily data, like a report |
WEEK_IN_SECONDS | 604,800 | Weekly data, like a post list |
The handbook also defines MONTH_IN_SECONDS as 30 days and YEAR_IN_SECONDS as 365 days. Pick the shortest lifetime that still saves real work, since a shorter lifetime means fresher data.
What is the difference between a transient and an option?
An option stores a setting with no end date, while a transient stores cached data with an expiration time.
The Options API holds settings your site must keep, like the site title or a plugin's choices.
The Transients API holds data your code can rebuild, like a query result or an API reply. That split decides which one to use: if losing the value would lose real data, it belongs in an option.
Storage differs in one more way. A transient with an expiration time is not autoloaded, so WordPress skips it on pages that never ask for it. A transient with no expiration is autoloaded, which means WordPress loads it on every page, as the set_transient() reference notes.
Rows pile up in wp_options over time, and a bloated options table slows every page. Our database repair guide shows how to check the table when it grows.
When should you use a transient?
Use a transient for any value that is slow to build, safe to lose, and fine to reuse for a while.
Good fits include replies from outside services, heavy database queries, and rendered HTML blocks. The WordPress Developer Blog gives three examples: a list of 25 post IDs saved for a week, the HTML for five recent posts, and meme data from an outside API saved for one hour.
Each one avoids repeat work on every page load.
Heavy queries that run on every page are a common cause of high CPU use, and a transient is one way to run them less often.
Skip transients for data that must never vanish, like an order record or a user setting. Skip them for data that changes on every view, like a live stock count, because the cache would serve stale numbers.
How do you check transients on your site?
WP-CLI lists, reads, and clears transients from the command line, and it is the fastest way to inspect them.
The WP-CLI transient docs list seven subcommands: delete, get, list, patch, pluck, set, and type. wp transient list shows what is stored, wp transient get my-transient reads one value, and wp transient type reports whether transients live in the database or in an object cache.
Cleanup has two safe forms. wp transient delete --expired removes only entries past their end time; the docs example shows it deleting 12 expired transients. wp transient delete --all removes everything, and the docs example shows 14 deleted.
Back up first, since a bad delete cannot be undone. Our guide to backing up a WordPress database covers the steps.
What mistakes should you avoid with transients?
The three big mistakes are skipping the expiration time, using names over 172 characters, and treating expiration as a guarantee.
A transient with no expiration gets autoloaded on every page, so a pile of them can drag down each request. The set_transient() reference says names must be 172 characters or fewer, because WordPress adds its own prefixes in the database, and longer names fail without a clear error.
The wp_options column itself holds 191 characters at most, which leaves room for those prefixes. The limit has a history: Trac ticket 15058 records that, before WordPress 4.4, names over 45 characters failed in the same silent way.
Deleting every transient at once is a fourth mistake. It is safe in the sense that code rebuilds each value, but the rebuilds all hit at once, so the next wave of visitors pays the full cost.
Clear only expired entries first, and delete single transients by name when you know which one is stale.
What myths about transients are wrong?
Three common myths are that expiration is exact, that transients always speed up a site, and that deleting them breaks things.
Expiration is a maximum, not a timer. A transient can vanish early when an object cache is flushed or the database changes, so code must always handle a miss.
A transient with no expiration can slow a site down instead of speeding it up, because WordPress loads it on every page whether it is used or not.
Deleting transients never breaks a site on its own. Each value is rebuilt the next time code asks for it, so the cost is a slower page or two, not an error.
A transient also caches one value inside WordPress, while page caching saves whole pages, and our guide to caching plugins on LiteSpeed hosting covers the page-caching side. Expired transients are not always cleaned up right away, since the handbook notes that WordPress only clears them out from time to time.
Frequently asked questions
Do transients slow down WordPress?
They usually speed it up, since they replace slow queries and outside requests with a quick read. They only slow a site down when they have no expiration time, because WordPress then autoloads them on every page. Always set an expiration, even a short one, and clear expired entries now and then.
Are transients deleted when they expire?
Not always right away. WordPress removes an expired transient when code tries to read it, and it clears old entries out from time to time, so stale rows can sit in the database for a while. WP-CLI can remove them on demand with wp transient delete --expired.
What is the difference between a transient and the object cache?
The object cache holds values in memory for one page load only, unless a persistent drop-in is installed. Transients use the object cache when one is present, and fall back to the database when it is not. That fallback is why transients work on any host.
Can I delete all transients safely?
Yes, deleting them does not break a site, because code rebuilds each value the next time it is needed. The cost is slower pages while the cache refills, so delete only expired entries on a busy site, and back up the database first.
When should I use an option instead of a transient?
Use an option for settings and data that must never disappear, like a plugin choice or a site title. Use a transient only for data your code can rebuild, like a query result or an API reply. If losing the value would lose real data, it belongs in an option.
Sources
- An introduction to the Transients API WordPress Developer Blog
- Transients WordPress Developer Resources
- set_transient() WordPress Developer Resources
- wp transient WP-CLI
- Redis Redis
- Memcached Memcached
Is your product missing, or something out of date?
Tell us what to add or correct. We read every note and reply when we need a source. A message does not buy a ranking.
Thanks — we review requests within 3 business days.
Related guides
About the editors
Researched from the primary sources listed above and checked against our editorial rules before publishing.


