Skip to content

WordPress trash management — emptying, retention, and recovery

A WordPress trash holds posts, pages, comments, and attachments for 30 days by default. How to tune retention, audit the queue, and recover items before the auto-purge.

A WordPress site’s database has grown to 8 GB and a quick audit reveals 60% of wp_posts is in the trash. The default trash retention of 30 days holds every deleted post, page, attachment, and comment until a daily cron empties them. On a small site this is invisible; on a publisher trashing hundreds of drafts a week, it becomes a meaningful storage cost and a recovery gap when no one realizes things still exist.

What’s happening

When a user clicks Move to Trash on a post, WordPress sets post_status = 'trash' and adds a _wp_trash_meta_status postmeta entry. The post still exists in wp_posts, hidden from queries that filter by published status. A WP-Cron job named wp_scheduled_delete runs daily and permanently deletes posts whose trash timestamp is older than EMPTY_TRASH_DAYS (default 30).

Comments work the same way (comment_approved = 'trash'). Attachments behave slightly differently — moving an attachment to trash does not delete the underlying file; only emptying the trash calls wp_delete_attachment() which removes the file from disk and triggers delete_attachment hook (where offload plugins remove the S3 copy).

How to verify

wp post list --post_status=trash --format=count
wp post list --post_status=trash --format=count --post_type=any

wp db query "SELECT post_type, COUNT(*), ROUND(SUM(LENGTH(post_content))/1024/1024, 2) as size_mb FROM wp_posts WHERE post_status='trash' GROUP BY post_type;"

wp comment list --status=trash --format=count

wp cron event list | grep wp_scheduled_delete
wp eval 'echo EMPTY_TRASH_DAYS . PHP_EOL;'

Pull the oldest trashed item: wp post list --post_status=trash --orderby=date --order=asc --posts_per_page=1 --fields=ID,post_title,post_date,post_type. If the date is older than EMPTY_TRASH_DAYS, the scheduled delete isn’t running.

The fix

  1. Tune EMPTY_TRASH_DAYS to the editorial reality. A newsroom that recovers accidental deletes within a day can set define('EMPTY_TRASH_DAYS', 7); in wp-config.php. A long-form publisher that may want to recover work weeks later keeps 30. Setting it to 0 disables trash entirely — deletes go straight to permanent, which is dangerous for client sites.
  2. Confirm the cron is running. If wp cron event list shows wp_scheduled_delete overdue, WP-Cron isn’t firing reliably. Switch to system cron: define('DISABLE_WP_CRON', true); then a real crontab entry hitting wp-cron.php every 5 minutes.
  3. Empty trash on demand for storage-pressured sites. wp post delete $(wp post list --post_status=trash --format=ids) --force permanently deletes every trashed post. Run after backup, not before.
  4. Audit attachment trash separately. Attachments in trash still consume disk. wp post list --post_status=trash --post_type=attachment --fields=ID,post_title lists them. On a media-heavy site, the trashed attachments may be the largest single bucket.
  5. Build a recovery workflow. Document who can recover a trashed post (Editors, Admins), how to find it (Posts > Trash, Pages > Trash, Media > List > Trash filter), and the SLA for recovery requests. Without process, recoveries become an emergency every time. The Enterprise WordPress operating model includes recovery procedures in the standard runbook so the first restore is not the live one.

Stack Harbor’s Enterprise WordPress operating model includes trash and retention policies as part of standard onboarding. When the database has bloated from old trash and no one has cleaned it in years, start the conversation.