← Back to All Snippets

Clean Up Expired Transients from WordPress Database with One Query

⚡ Target: phpMyAdmin / WP-CLI db query 🔒 Tested: MySQL 8.0+ / MariaDB 10.4+ 💻 Lang: SQL
⚠️ Database Table Prefix Reminder: This query uses the standard wp_ table prefix (e.g. wp_options, wp_postmeta). If your installation uses a custom table prefix (configured in wp-config.php, e.g. wp_a7b_), be sure to replace wp_ with your custom prefix before running this query.
SQL (phpMyAdmin / WP-CLI db query)
DELETE a, b 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_value < UNIX_TIMESTAMP();

Expired transients often accumulate into tens of thousands of unused rows in wp_options, inflating database backup size and slowing autoloaded options. This SQL query safely purges expired transients.

← Back to All Snippets Explore Dev Tools →