How Can We Help?
Bulk Entry Delete
[vc_row][vc_column][vc_column_text]
Issue
You have a large amount entries that you want to delete based on some criteria, e.g., all entries that are older than 14 days.
Use Case
Client is a Wildlife park and wishes to purge all ticket sales for days more than 14 days in the past.
Solution
Write a small PHP function to loop over entries, check a specific criteria and then delete entries matching that criteria. Additionally, you can create a CRON job to run this program every night (or at whatever frequency you wish).
Credits to
Martin Koss (@Martin Koss on Formidable Slack) for having the problem that needed to be solved.
Non-Code Changes
N/A
Caveats
For the love of Pete, back up your database AND test the function with echo commands, rather than the actual delete, to make sure your logic is correct, before making the script live.
Code
[/vc_column_text][vc_raw_html]JTNDYmxvY2txdW90ZSUzRSUwQSUzQ3ByZSUzRSUwQSUwOSUyNHBhdGglMjAlM0QlMjBwcmVnX3JlcGxhY2UlMjglMjclMkZ3cC1jb250ZW50LiUyQSUyNCUyRiUyNyUyQyUyNyUyNyUyQ19fRElSX18lMjklM0IlMEElMDlyZXF1aXJlJTI4JTI0cGF0aCUyMC4lMjAlMjclMkZ3cC1sb2FkLnBocCUyNyUyOSUzQiUwQSUwQSUwOWRlZmluZSUyOCUyMCUyN0ZPUk1fS0VZX1RJQ0tFVF9PUkRFUlMlMjclMkMlMjAlMjdkYXktcGFzcy1zdHJpcGUlMjclMjklM0IlMjAlMkYlMkYlMjBrZXklMjBvZiUyMHRoZSUyMGZvcm0lMjB5b3UlMjdyZSUyMGRlbGV0aW5nJTIwZnJvbSUwQSUwOWRlZmluZSUyOCUyMCUyN0ZJRUxEX0tFWV9USUNLRVRfREFURSUyNyUyQyUyMCUyN3ZwYmt6JTI3JTI5JTNCJTIwJTJGJTJGJTIwa2V5JTIwb2YlMjB0aGUlMjBmaWVsZCUyMHRoYXQlMjB5b3UlMjdyZSUyMGNoZWNraW5nJTIwZm9yJTIwdGhlJTIwZGF0ZSUyMGNvbXBhcmlzb24lMEElMEElMDklMjRmb3JtSWQlMjAlM0QlMjBGcm1Gb3JtJTNBJTNBZ2V0X2lkX2J5X2tleSUyOEZ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