# Remove Completed Privacy Requests After 90 Days

> Deletes finished export and erasure requests (and failed ones) from Tools > Export/Erase Personal Data once they are 90 days old, since the request records themselves contain email addresses.

- Type: PHP
- Runs: Run everywhere
- Category: [Privacy & Cookies](https://wpide.com/library/category/privacy/)
- Tags: gdpr, retention, cron
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/privacy-clean-old-privacy-requests/

## Code

```php
// Age in days after which finished requests are removed.
$wpide_request_days = 90;

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

add_action( 'wpide_clean_privacy_requests', function () use ( $wpide_request_days ) {
    $ids = get_posts( array(
        'post_type'      => 'user_request',
        'post_status'    => array( 'request-completed', 'request-failed' ),
        'posts_per_page' => 100,
        'fields'         => 'ids',
        'no_found_rows'  => true,
        'date_query'     => array( array( 'column' => 'post_modified_gmt', 'before' => $wpide_request_days . ' days ago' ) ),
    ) );

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

## Notes

Keep records longer if you need them as proof that requests were handled.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Remove Completed Privacy Requests After 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/
