How to delete a the items in a database automatically after a certain time of its creation .
Use Case:
When the user inputs the data to a form, he can choose when to delete the data from the database automatically using a date picker (maximum 3 months from current date). So that the database will be rid of old data and the user need not bother about it as after 3 months or after the user selected date, it gets automatically deleted.
Research:
I have read this post and comment from @Yisrael . But in that code, the admin must go to the page everyday to delete the contents (now the code is deleting all data but i know how to delete it based on date by comparing the dates ).
What I Want:
What I want is automatic deletion (from all the databases in my website )without admin doing anything. Is there any way to achieve this? Maybe using hooks? or any other way which removes the manual work and doesnāt impact on site load speed or database access speed.
I suggest that you implement it using http functions .
Once you have a function that handles deletion, you can trigger it manually or using an automation service such as Zappier or IFTTT.
Hi, it worked but my live site stills showing those items as the deleted items still present in live database , i also tried syncing the database (sandbox) with live database still no luck its just copying those items to live but not to replacing the live database ? help me solve it , once the item is deleted in the database (sandbox) i want it to be deleted from live site also. how to do it.
@vamsi Make sure that you delete items when running the Live site. The sandbox and Live databases are completely separate. When you delete from a Preview, the item will only be deleted from the Sandbox database. If you delete from a Live site, the item will only be deleted from the Live database.
@yisrael-wix Thanks for the heads up , but how to delete items from live database when the site is live ? in the same code replacing with live database name instead of sandbox database name works?
hi @ Ukaz Zaku , im able to delete only one item per page load does your code delete all the items in one go ? can we delete all items which expiry date is lesser than today in one go ?