Database Optimization

WordPress Transients Explained: How to Find and Delete Expired Transients

Where WordPress keeps transients, what the daily sweep misses, and how to delete expired ones safely with WP-CLI or SQL, with and without Redis.

Varun DubeyVarun Dubey
·13 min read
Four wp_options rows showing which expired transient rows core deletes and which it leaves behind

WordPress stores each database transient as a pair of rows in the wp_options table, a value row named _transient_{key} and a timeout row named _transient_timeout_{key}. WordPress deletes an expired pair when something reads that key, and a daily core event called delete_expired_transients sweeps the rest, but only on sites that are not using an external object cache. To clear them by hand, run wp transient delete --expired, or the SQL further down, after a database backup.

That is the short version. The rest of this guide covers what the daily sweep misses, what changes when Redis or Memcached is active, which flags do what, and how to run the cleanup without hurting a live site. Checked on 15 Nov 2026: every function, hook and command below was read against the WordPress core source (trunk, 7.2 beta 5), the WordPress developer reference and the WP-CLI cache-command source. WordPress 7.1 is the current release.

Not every site needs this. If wp transient list --format=count returns a few hundred rows, leave it alone. The cleanup matters when the count is in the tens of thousands, when a table export is getting slow, or when you have just switched on a persistent object cache and want the old rows gone.

What are transient options in wp_options?

People search for “transient options” because the data shows up in the options table and looks like a setting. It is not a setting. A transient is a cached value with an optional lifetime, and on a default WordPress install the Transient API keeps it in wp_options because that table is the one place every host provides.

The functions are set_transient(), get_transient() and delete_transient(), plus site-wide twins named set_site_transient() and friends. Calling set_transient( 'my_key', $value, HOUR_IN_SECONDS ) on a site with no object cache writes two rows:

option_name                        option_value   autoload
_transient_timeout_my_key          1763200000     off
_transient_my_key                  (your value)   off

The timeout row holds a Unix timestamp. The value row holds your data, serialized if it is an array or object. The table below shows the four prefixes you will meet and where each one lives.

Row prefix

What it is

Stored in

_transient_

Value of a normal transient

wp_options of the current site

_transient_timeout_

Expiry timestamp for that value

wp_options of the current site

_site_transient_

Value of a site transient, for example plugin update checks

wp_options on a single site, wp_sitemeta on a multisite network

_site_transient_timeout_

Expiry timestamp for a site transient

Same table as its value row

One detail that matters for the autoload section later: when you pass an expiration, core writes both rows with autoload off. When you pass 0 or leave the argument out, no timeout row is written and the value row is autoloaded. We read that straight from the set_transient() source, and it is the root of most “my options table is huge” stories.

Does WordPress delete expired transients on its own?

Yes, in two ways, and both have gaps. The first is lazy deletion. When get_transient() finds a timeout row in the past, it deletes the value and timeout rows and returns false. If nothing ever asks for that key again, the expired pair stays where it is. A plugin that cached a one-off API response and then stopped calling it leaves exactly this kind of row behind.

The second is the daily sweep. Since WordPress 4.9.0 core has a function called delete_expired_transients(). It is hooked to an event of the same name, delete_expired_transients, and the event is scheduled daily. Two source details are worth knowing:

  • The event is created in wp-admin/admin.php, when no delete_expired_transients event is queued. In practice it appears the first time any wp-admin page loads after it goes missing, and it only runs when WP-Cron actually fires.
  • The function returns at once when wp_using_ext_object_cache() is true, unless the caller passes $force_db = true. The developer reference says it plainly: the function does nothing if an external object cache is in use.

A common mix-up is worth clearing up. The daily event that empties the trash and old auto-drafts is wp_scheduled_delete, which is a different hook. Transients have their own event. If you are checking whether cleanup is scheduled, look for the right name:

# Checked on 15 Nov 2026
wp cron event list --fields=hook,next_run_relative,recurrence | grep -E 'delete_expired_transients|wp_scheduled_delete'

# Run the core sweep once, right now (does nothing if an external object cache is active)
wp cron event run delete_expired_transients

What the daily sweep never touches

The core query pairs each value row with its timeout row and deletes both when the timeout is in the past. Anything that does not fit that pairing survives. That covers four cases we see regularly:

  • Transients with no expiration. No timeout row, so the join finds nothing. These are permanent until something deletes them by name.
  • Timeout rows whose value row is gone. The join starts from the value row, so a lone timeout row is never matched.
  • Unexpired transients from a plugin you removed. They go once they expire, so a plugin that used long lifetimes leaves rows around for weeks.
  • Everything, when an object cache is loaded. The sweep exits early, so rows written before you added Redis are never cleaned by core.

If your cron is unreliable, the daily event is unreliable too. Our guide on monitoring WP-Cron and Action Scheduler failures shows how to tell a missed run from a run that never happened.

How do I check how many expired transients I have?

Count first, delete second. These queries are read-only. Replace wp_ with your table prefix, and note the escaped underscores: in SQL LIKE, an unescaped underscore matches any single character, which is why core builds its patterns with esc_like().

-- Checked on 15 Nov 2026. Read-only. Total transient rows and their size.
SELECT COUNT(*) AS total_rows,
       ROUND(SUM(LENGTH(option_value)) / 1024 / 1024, 2) AS size_mb
FROM wp_options
WHERE option_name LIKE '\_transient\_%'
   OR option_name LIKE '\_site\_transient\_%';
-- Expired value rows (same pairing the core sweep uses)
SELECT COUNT(*) AS expired_transients
FROM wp_options a
JOIN wp_options b
  ON b.option_name = CONCAT('_transient_timeout_', SUBSTRING(a.option_name, 12))
WHERE a.option_name LIKE '\_transient\_%'
  AND a.option_name NOT LIKE '\_transient\_timeout\_%'
  AND b.option_value < UNIX_TIMESTAMP();
-- Timeout rows with no value row (orphans the core sweep cannot match)
SELECT COUNT(*) AS orphan_timeouts
FROM wp_options t
LEFT JOIN wp_options v
  ON v.option_name = CONCAT('_transient_', SUBSTRING(t.option_name, 20))
WHERE t.option_name LIKE '\_transient\_timeout\_%'
  AND v.option_id IS NULL;
-- Value rows with no timeout row (never expire), largest first
SELECT a.option_name, LENGTH(a.option_value) AS bytes, a.autoload
FROM wp_options a
LEFT JOIN wp_options b
  ON b.option_name = CONCAT('_transient_timeout_', SUBSTRING(a.option_name, 12))
WHERE a.option_name LIKE '\_transient\_%'
  AND a.option_name NOT LIKE '\_transient\_timeout\_%'
  AND b.option_id IS NULL
ORDER BY bytes DESC
LIMIT 20;

The numbers in the substring calls are character counts: _transient_ is 11 characters, so the key starts at position 12, and _transient_timeout_ is 19, so its key starts at 20. They should also stay cheap on large tables, because option_name is a unique index and every pattern is a prefix match. The LIMIT 20 on the last query keeps the output readable.

The same audit with WP-CLI

# Checked on 15 Nov 2026 (WP-CLI 2.12.0)
wp transient type                       # database or object cache?
wp transient list --format=count        # how many (database only)
wp transient list --fields=name,expiration --human-readable | head -30

wp transient type is the quickest way to learn where your transients really go. It prints either “Transients are saved to the database” or “Transients are saved to the object cache”. The list command only shows database rows and prints a warning when an external cache is active, so a count of zero on a Redis site means “none in the database”, not “none exist”.

What is the safest way to delete expired transients?

Use WP-CLI when you have it, take a backup first, and delete expired rows before you consider deleting everything. Expired rows are dead by definition. Nothing can read them again, because get_transient() would already have removed and ignored them.

# Checked on 15 Nov 2026
wp db export ~/backup-before-transients-$(date +%F).sql

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

# Site transients (on multisite this is the network-wide set)
wp transient delete --expired --network

Here is a correction to something many guides repeat, including an earlier version of this one. wp transient delete --expired does not call the core delete_expired_transients() function. The WP-CLI command runs its own multi-table DELETE, built the same way as the core query, and it runs against the database whether or not an object cache is active. If an object cache is active, it deletes the database rows and then prints a warning that cached transients are untouched. That is why it is the right tool for clearing legacy rows after you add Redis.

If you would rather run the core function itself, with the object-cache check switched off, use wp eval:

# Checked on 15 Nov 2026. Runs core's own sweep and forces it onto the database.
wp eval 'delete_expired_transients( true );'

Multisite

On a network, normal transients are per site and site transients are network-wide and stored in wp_sitemeta. The WP-CLI docs show the pattern for covering every site. Adapted for expired rows it looks like this:

# Checked on 15 Nov 2026
wp transient delete --expired --network \
  && wp site list --field=url | xargs -n1 -I % wp --url=% transient delete --expired

Choosing a method

Method

Deletes

Touches object cache

Use it when

Core daily event

Expired pairs in the database

No, and skips entirely if one is active

Default behaviour, nothing to do

wp transient delete --expired

Expired pairs in the database

No (prints a warning)

Routine cleanup, or legacy rows after adding a cache

wp transient delete --all

Every database transient, expired or not, with or without a timeout

No (prints a warning)

One-time reset, for example right after enabling a persistent cache

Raw SQL

Whatever your query matches

No

No shell access; you accept the risk of a typo

wp cache flush

Everything in the object cache, not only transients

Yes

Clearing cached transients on a Redis or Memcached site

Is it safe to delete all transients?

Expired ones, always. All of them, almost always. A transient is disposable by contract: the code that wrote it is supposed to rebuild it when get_transient() returns false. The cost of wp transient delete --all is a burst of rebuilding work, such as plugin update checks going back out to wordpress.org, feed caches refetching and any cached query running again.

On a busy site, do that at a quiet hour so a few hundred visitors do not trigger the same rebuild at once. And read the exceptions before you run it on a client site:

  • Some plugins store things in transients that are not really cache: one-time admin notices, short-lived login or OAuth state, rate-limit counters and job locks. Deleting those can log someone out of an integration or let a duplicate job run once.
  • A transient with no expiration may be something a developer meant to keep. Run the “never expire” query above and look at the names before you delete them in bulk.
  • If you disable your object cache later, old database rows that were written before you enabled it and have not yet expired would be read again. Clearing them while you migrate avoids stale values returning.

What does safe SQL with a backup look like?

If you cannot use WP-CLI, run the SQL in phpMyAdmin, Adminer or the MySQL client, in this order: back up, count, delete, count again. The delete statement below is the one core uses, with the prepared values filled in. It deletes the value row and its matching timeout row in one pass.

-- Checked on 15 Nov 2026
-- 1. Backup first (shell):  wp db export ~/backup-before-transients-$(date +%F).sql
-- 2. Run the "expired_transients" count query from above and note the number.
-- 3. Delete expired pairs (normal transients):
DELETE a, b
FROM wp_options a, wp_options b
WHERE a.option_name LIKE '\_transient\_%'
  AND a.option_name NOT LIKE '\_transient\_timeout\_%'
  AND b.option_name = CONCAT('_transient_timeout_', SUBSTRING(a.option_name, 12))
  AND b.option_value < UNIX_TIMESTAMP();

-- 4. Delete orphan timeout rows (timeout with no value row):
DELETE t
FROM wp_options t
LEFT JOIN wp_options v
  ON v.option_name = CONCAT('_transient_', SUBSTRING(t.option_name, 20))
WHERE t.option_name LIKE '\_transient\_timeout\_%'
  AND v.option_id IS NULL;

For site transients on a single site, repeat the first delete with _site_transient_ (16 characters, so the key starts at 17) and _site_transient_timeout_. On multisite, site transients live in wp_sitemeta with meta_key and meta_value instead.

Three habits keep this boring:

  • Run the count before and after, and compare. If the delete removed far more than the count said, stop and restore.
  • Do not write a blanket DELETE FROM wp_options WHERE option_name LIKE '%transient%'. Without escaping, that pattern also matches options that merely contain the word, and a plugin setting called something like my_transient_mode would go with it.
  • On a table with hundreds of thousands of transient rows, run it at a quiet hour. It is a single statement that locks the rows it deletes, and your site is reading and writing the same table.

Where are transients stored with Redis or Memcached?

In the cache, not in wp_options. When an external object cache is active, set_transient() calls wp_cache_set() in the transient group and no rows are written. The cache backend enforces the lifetime. That is why delete_expired_transients() exits early on those sites: there is nothing in the database to clean.

Setup

Where transients live

Who removes expired ones

No object-cache.php drop-in

wp_options (wp_sitemeta for site transients on multisite)

Lazy deletion on read, plus the daily core event

Persistent drop-in (Redis, Memcached, Valkey)

The cache server

The cache server, by TTL or eviction

The condition core checks is wp_using_ext_object_cache(), which becomes true when an object-cache.php drop-in is loaded. A plugin dashboard can say “connected” while the drop-in file is missing or was overwritten, in which case writes quietly go back to the database. Do not trust the dashboard. Run wp transient type. We cover the layers in WordPress caching, layer by layer.

Old rows after you switch the cache on

Core does not clean up after the switch. Rows written before you enabled Redis stay in wp_options. They are no longer read, because get_transient() now asks the cache, so they are dead weight in the table and in every export. This is where the flags differ:

  • wp transient delete --expired removes only the ones whose timeout has passed. Unexpired rows disappear on later runs as their timestamps pass, which is fine for small leftovers.
  • wp transient delete --all removes every database transient, including those with no timeout. Run it once after the switch, then confirm with wp transient list --format=count that the database count is near zero.
  • Neither command touches the cache, so there is nothing to “rebuild” in Redis afterwards. The rebuild cost comes from wp cache flush.

The Redis Object Cache plugin changed its own behaviour here: a pull request opened in October 2025 and merged, titled “Delete transients when activating cache”, exists to avoid stale WooCommerce data from old rows. If you use a different drop-in, do the cleanup yourself.

Do transients affect autoload performance?

Only the ones without an expiration. Autoloaded options are fetched in one query on every request and held in memory, so a large autoloaded row costs time on every page. Transients with a lifetime are written with autoload off and never join that group. A transient set with $expiration = 0 is written with autoload on. In WordPress 6.6 and later the autoloaded values are yes, on, auto-on and auto, which core lists in wp_autoload_values_to_autoload().

# Checked on 15 Nov 2026. Autoloaded transient rows, biggest last.
wp option list --search='*_transient_*' --autoload=on --fields=option_name,size_bytes | sort -n -k 2 | tail -20

# Total autoloaded bytes for the whole table, for context
wp option list --autoload=on --format=total_bytes

Expired rows that are not autoloaded are a size and housekeeping problem, not a per-request problem. They make backups bigger and some plugin queries slower. We will not promise a page speed gain from deleting them, and you should be wary of any guide that does. If you see a slow site and a big options table together, check the autoload total first. Our write-up on wp_options autoload bloat covers that route.

Here is the correct way to write a transient so it never turns into a permanent autoloaded row:

<?php
// Checked on 15 Nov 2026. Cache a remote response for six hours.
function twp_get_exchange_rates() {
	$rates = get_transient( 'twp_exchange_rates' );
	if ( false !== $rates ) {
		return $rates;
	}

	$response = wp_remote_get( 'https://api.example.com/rates' );
	if ( is_wp_error( $response ) ) {
		return array();
	}

	$rates = json_decode( wp_remote_retrieve_body( $response ), true );
	if ( ! is_array( $rates ) ) {
		return array();
	}

	// A real expiration keeps both rows out of the autoload query.
	set_transient( 'twp_exchange_rates', $rates, 6 * HOUR_IN_SECONDS );

	return $rates;
}

// In uninstall.php, remove it when the plugin goes away.
// delete_transient( 'twp_exchange_rates' );

Data that has to survive should not be a transient at all. Settings belong in options, per-user data in user meta, and anything you cannot afford to lose on a cache flush needs a table of its own.

Why do expired transients keep coming back?

Because something keeps creating them, and one key per request is the usual cause. A transient is only cheap if its key is stable. A plugin that builds the key from a search term, a URL, a user ID plus a timestamp or a query hash creates a new pair for each variation, and each pair outlives its usefulness by days.

Group your rows by key prefix to find the producer. The query strips the leading _transient_ and groups by the first two underscore-separated parts of the key:

-- Checked on 15 Nov 2026. Read-only. Biggest transient producers by key prefix.
SELECT SUBSTRING_INDEX(SUBSTRING(option_name, 12), '_', 2) AS key_prefix,
       COUNT(*) AS rows_found,
       ROUND(SUM(LENGTH(option_value)) / 1024) AS size_kb
FROM wp_options
WHERE option_name LIKE '\_transient\_%'
  AND option_name NOT LIKE '\_transient\_timeout\_%'
GROUP BY key_prefix
ORDER BY rows_found DESC
LIMIT 20;

Match the top prefixes to plugin slugs, then decide: configure the plugin, replace it, or accept the churn. Do not guess from a list of “usual suspects” online. Key naming is up to each author and changes between versions, so only your own table tells you the truth.

Other causes we see:

  • WP-Cron is stuck. No cron means no daily sweep, and the lazy deletion path only covers keys that are read again.
  • Plugin removed, rows stayed. Deleting a plugin does not delete its transients unless its uninstall routine does it.
  • A persistent cache was switched off. Transients move back to the database and the old rows from before the switch reappear.

Should I schedule the cleanup myself?

Rarely, and never by adding a second PHP cron job that duplicates core. The core event already runs daily when WP-Cron is healthy. Add your own schedule only for two reasons: your WP-Cron is disabled and replaced by a system cron, or you run a persistent object cache and want a one-off sweep of legacy rows.

With a system cron and WP-CLI, a weekly line is enough:

# Checked on 15 Nov 2026. Weekly, Sunday 03:15, quiet output.
15 3 * * 0 cd /var/www/html && wp transient delete --expired --quiet

If DISABLE_WP_CRON is on and nothing replaces it, the daily core event never runs. Fix that first, and the transient cleanup follows.

Common mistakes people report

These come from public issue trackers and the WP-CLI source, paraphrased. Each link was opened on 15 Nov 2026.

  • Expecting wp transient delete to clear cached transients. The command deletes database rows and says so with a warning when an external cache is active. The cache is untouched. Source: WP-CLI cache-command source.
  • Flushing the whole object cache to “clean transients”. A Redis Object Cache issue opened in March 2025 describes the side effect: flushing removes every stored transient, including ones far from expiry, and expensive ones such as the plugin update check have to be rebuilt. Source: redis-cache issue 568.
  • Leaving old rows in place after enabling Redis. The plugin’s maintainers merged a change, opened in October 2025, to delete transients when the cache is activated, to avoid stale WooCommerce data. Source: redis-cache pull request 589.
  • Forgetting site transients and the --network flag. A 2018 WP-CLI issue pointed out that the delete command skipped some of core’s three storage cases. The current command covers them, and the docs describe the flag for network transients. Sources: cache-command issue 41 and the wp transient delete docs.
  • Using a transient as a lock. A 2024 report describes two async jobs sharing a lock stored as a transient, where the second job still saw the lock after the first had deleted it. Transients are a cache, not a mutex. Source: redis-cache issue 523.

None of these are bugs in your site’s data. Each is a wrong assumption about where transients live or what a command touches.

Frequently asked questions

How often should I clean expired transients?

On a site where the daily core event runs, you do not need to do anything. Check the schedule with the cron command above. Where WP-Cron is replaced by a system cron or the count keeps growing, a weekly wp transient delete --expired is plenty.

Will deleting transients make my site faster?

It can shrink the table and backups, and it can speed up queries that scan wp_options. It will not speed up page loads unless autoloaded transients (the ones with no expiration) were large. Measure the autoload total before and after instead of assuming.

Is a plugin better than WP-CLI for this?

A plugin is fine if you have no shell access, and several database cleanup plugins include a transient option. They run the same kind of delete. What matters is that you can see a count first and that you back up the database.

Can I delete transients while the site is live?

Yes. Expired transients are unreachable by definition, and unexpired ones rebuild on demand. The risk is load, not correctness, so pick a quiet hour for --all.

Why does WP-CLI show zero transients on my Redis site?

Because wp transient list only reads the database. With an external cache active, your transients are in Redis. Use wp transient type to confirm, and use Redis tooling or the plugin’s own diagnostics to inspect cached keys.

What changed in WordPress 7.x about transients?

Nothing we could find that changes the behaviour described here. The cleanup function has the same signature and early exit as when it was introduced in 4.9.0, and the source we read for this update is the 7.2 development branch. If a later release changes it, the developer reference page for delete_expired_transients() will show it in the changelog.

When should I leave transients alone?

When the count is small, when your object cache is healthy and the database holds none, and when no export or backup is struggling. Cleaning a clean table is busywork, and it is one more command you can get wrong on a live site.

Related reading on this site: limiting and cleaning post revisions covers the other big source of table growth, and 11 WordPress database mistakes lists the habits that make cleanups necessary.

Part of the Wbcom Designs family

The all-in-one WordPress community stack

Also ours: wbcomdesigns.comvapvarun.combrndle.com