wp transient delete-expired
Overview
Remove only expired transients from wp_options — a safe, conservative cleanup that doesn't touch valid cached data. Ideal for routine database maintenance on sites with many plugins that use the transient API heavily.
What It Does
WordPress does not automatically purge expired transients from the database when a persistent object cache (like Redis or Memcached) is not in use. On sites using the default database transient storage, expired transients accumulate indefinitely and bloat wp_options. wp transient delete-expired safely removes them.
Syntax
wp transient delete-expired [--network]
Options
| Flag | Description |
|---|---|
--network | Delete expired network transients (multisite) |
Basic Usage
wp transient delete-expired
Output:
Success: 123 expired transients deleted from the database.
With Network Transients
wp transient delete-expired --network
Output:
Success: 18 expired network transients deleted from the database.
Real-World Scenarios
Scenario 1: Scheduled weekly cleanup via Cron
# /opt/scripts/wp-transient-cleanup.sh
#!/bin/bash
wp transient delete-expired
wp transient delete-expired --network 2>/dev/null # multisite only
# crontab — run every Sunday at 3 AM
0 3 * * 0 /opt/scripts/wp-transient-cleanup.sh
Scenario 2: Pre-deployment database optimisation
wp transient delete-expired
wp db optimize
echo "Database cleaned and optimised before deploy."
Scenario 3: Audit before and after
echo "Before: $(wp transient list --format=count) transients"
wp transient delete-expired
echo "After: $(wp transient list --format=count) transients"
Output:
Before: 165 transients
After: 42 transients
delete-expired vs delete --all
| Command | Risk | Use When |
|---|---|---|
wp transient delete-expired | None — only removes expired | Routine maintenance |
wp transient delete --all | Clears ALL transients (active + expired) | Full reset, post-migration |
Best Practices
- Run weekly via cron on sites that don't use Redis/Memcached.
- Run before
wp db optimizeso the optimisation actually reclaims freed space. - Pair with
wp cache flushpost-deploy to ensure a fully clean state. - Use
--networkin multisite setups — it targets a separate set of transients.
Quick Reference
wp transient delete-expired # Standard
wp transient delete-expired --network # Multisite
wp transient list --format=count # Count before/after
Next Steps
wp transient delete— delete specific transients.wp transient list— audit what transients are stored.wp cache flush— flush the full object cache.