# Delete Old Contact Form 7 Messages Stored in Flamingo

> Permanently deletes contact form messages saved by the Flamingo add-on once they are older than 180 days, so old enquiries and their personal data are not kept forever.

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

## Code

```php
// Days to keep stored messages.
$wpide_flamingo_days = 180;

add_action( 'init', function () {
    if ( post_type_exists( 'flamingo_inbound' ) && ! wp_next_scheduled( 'wpide_flamingo_retention' ) ) {
        wp_schedule_event( time() + HOUR_IN_SECONDS, 'daily', 'wpide_flamingo_retention' );
    }
}, 20 );

add_action( 'wpide_flamingo_retention', function () use ( $wpide_flamingo_days ) {
    if ( ! post_type_exists( 'flamingo_inbound' ) ) {
        return;
    }

    $ids = get_posts( array(
        'post_type'      => 'flamingo_inbound',
        'post_status'    => 'any',
        'posts_per_page' => 200,
        'fields'         => 'ids',
        'no_found_rows'  => true,
        'date_query'     => array( array( 'before' => $wpide_flamingo_days . ' days ago' ) ),
    ) );

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

## Notes

Requires the Flamingo plugin alongside Contact Form 7; nothing happens if Flamingo is not active.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Delete Old Contact Form 7 Messages Stored in Flamingo" 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/
