Skip to main content

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​

FlagDescription
--networkDelete 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​

CommandRiskUse When
wp transient delete-expiredNone — only removes expiredRoutine maintenance
wp transient delete --allClears ALL transients (active + expired)Full reset, post-migration

Best Practices​

  1. Run weekly via cron on sites that don't use Redis/Memcached.
  2. Run before wp db optimize so the optimisation actually reclaims freed space.
  3. Pair with wp cache flush post-deploy to ensure a fully clean state.
  4. Use --network in 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​