# Delete Comments Left Unmoderated for 90 Days

> Once a day, permanently deletes comments that have been waiting in the moderation queue for more than 90 days, along with the names, emails and IP addresses they contain.

- Type: PHP
- Runs: Run everywhere
- Category: [Privacy & Cookies](https://wpide.com/library/category/privacy/)
- Tags: comments, retention, moderation
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/privacy-delete-stale-pending-comments/

## Code

```php
// Days a comment may wait for moderation.
$wpide_pending_days = 90;

add_action( 'init', function () {
    if ( ! wp_next_scheduled( 'wpide_delete_stale_pending' ) ) {
        wp_schedule_event( time() + HOUR_IN_SECONDS, 'daily', 'wpide_delete_stale_pending' );
    }
} );

add_action( 'wpide_delete_stale_pending', function () use ( $wpide_pending_days ) {
    $ids = get_comments( array(
        'status'     => 'hold',
        'number'     => 200,
        'fields'     => 'ids',
        'date_query' => array( array( 'column' => 'comment_date_gmt', 'before' => $wpide_pending_days . ' days ago' ) ),
    ) );

    foreach ( $ids as $id ) {
        wp_delete_comment( (int) $id, true );
    }
} );
```

## Notes

Approve or reply to comments you want to keep before they reach the age limit.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Delete Comments Left Unmoderated for 90 Days" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
