Deleting old entries in bulk [RESOLVED]

Supporting a site with about 5,000 GF submissions across 6 forms - entries span about 4 years total. Client really only needs access to last year of submissions. Planning to backup site, create archive of older entries and leave only 18 months or so on production site.

Deleting them manually is doable, but wanted to see if better approaches exist. Ideally, I’d like to delete attachments also submitted with many entries.

Any advice appreciated.

Don’t have any ready code for this but I’m thinking you could run a simple function to call GFAPI::get_entries() to fetch all entries (across all forms) that are from before a given date and then loop through each entry and delete it via GAPI::delete_entry.

Hope that helps point you in the right direction!

1 Like

You can use https://docs.gravityforms.com/personal-data-settings/#retention-policy for each form. If you set this older entries are automatically deleted by GF. This function is triggered by the WordPress cron.

1 Like

Great ideas, guys. I’ll explore both approaches.

THANK YOU!

Possibly an easier way…I had the same need not too long ago (to remove thousands of old entries in bulk) and this is the answer I got, seems like it might work for you too:

" You can use the built in filter on the Entries page to search for ENTRY DATE “less than” and some date (like 2019-01-01 YYYY-MM-DD) and then when the search results are shown on the page, you should have 20 by default (this can be changed if you want by using the Screen Options pull down on the WordPress page.) No matter how many are shown on screen, you can use the “Select all” checkbox at the top of the list, and you will get a nifty message that says:

All 20 entries on this page are selected. Select all 1844 entries. (or whatever your numbers are)

“Select all 1844 entries” will be hyperlinked. If you click that link, you get a message that says “All 1844 entries have been selected” and now you can do whatever you want with them. In your case, you can use the Bulk Actions drop down to “Trash” them all. Select “Trash” then click “Apply” - that will mark them all as Trash. Click the Trash link, and then you can use the “Empty Trash” button or the “Select all” checkbox again and then the bulk action of “Delete Permanently”.

That will clear out entries older than the search criteria date you used.

If you want to automate this in the future to avoid the manual intervention, you could use this third-party plugin:

Entry Automation – Automatically export your Gravity Forms entries

Two additional tools for your deletion toolkit to consider:

These were all great suggestions but wound up using GF’s Personal Data retention tools and it worked like a champ but with a few caveats:

  1. Personal data is deleted by cron job so when entries actually get removed depends upon when your server runs GF maintenance cron jobs. They run once every 24 hours.

  2. If you also choose to remove any associated media (i.e. form uploads), that also happens by a cron job but at a different time than the job above. This also runs once every 24 hours.

I selected both options (remove entries and remove form uploads) then checked total number of entries 4 hours later. Entries older than 1 year had been removed but uploads associated with those entries were not removed until sometime overnight.

Worth noting that total size of site in gigabytes was reduced by more than half after uploads had been removed.

1 Like

Thanks for the update @crucesignati.