← Back to All Snippets

Delete Expired and Orphaned Transients from wp_options via SQL

⚡ Target: phpMyAdmin / SQL 🔒 Tested: WP 6.6+ / PHP 8.2+ 💻 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 / SQL)
-- 1. Delete expired transient timeouts
DELETE FROM wp_options 
WHERE option_name LIKE '_transient_timeout_%' 
AND option_value < UNIX_TIMESTAMP();

-- 2. Delete corresponding transient data rows that have timed out
DELETE o1 FROM wp_options o1 
JOIN wp_options o2 ON o2.option_name = CONCAT('_transient_timeout_', SUBSTRING(o1.option_name, 12)) 
WHERE o1.option_name LIKE '_transient_%' 
AND o1.option_name NOT LIKE '_transient_timeout_%' 
AND o2.option_value < UNIX_TIMESTAMP();

Clean thousands of abandoned and expired transient records from wp_options to instantly reduce database memory footprint and table fragmentation.

← Back to All Snippets Explore Dev Tools →