Home › Forums › Calendar Products › Events Calendar PRO › How do I batch delete hundreds of Events?
- This topic has 6 replies, 3 voices, and was last updated 9 years, 7 months ago by
Rodrigo Torres.
-
AuthorPosts
-
August 31, 2016 at 3:04 pm #1158454
Rodrigo Torres
ParticipantHi, We have hundreds of events on our current calendar at http://www.challengeday.org/calendar.php which we are looking to implement on a WP site using Events Calendar Pro. Every evening we delete all of the events and a script imports all of the events again. This way we take care of events that have moved dates or are no longer happening.
I only see a way to delete 20 events at a time and that won’t work for us.
How can we batch delete hundreds of events?
Additionally, if it can be automated that is really what we need.
Thank you!
RodrigoAugust 31, 2016 at 5:29 pm #1158506Nico
MemberHi there Rodrigo,
Thanks for reaching out to us!
I guess you could set up a cron job to take care of this, using wp_schedule_event is an option. Querying all events and using the WordPress function wp_delete_post could work, although if you have hundred of events you might want to be careful with performance issues. For example, maybe past events don’t need to be deleted, this will surely reduce the load.
If you are looking to mass delete the events from the WordPress interface then I’d recommend Bulk Delete plugin. I’m not sure about it but the plugin might have an API you can use instead of programming your own ‘reset events’ function.
One last thing, in any method you choose be sure to delete the event meta data as well!
Hope this helps you out,
Best,
NicoSeptember 1, 2016 at 1:25 pm #1158980Rodrigo Torres
ParticipantThanks! I still am not clear on how I would know which post ids to use with wp_delete_post or which event metadata to delete.
Also not clear on performance issues. Can you say more? I would think that the less rows in the db the faster the performance which would argue for deleting past events all together once they are no longer needed.
September 2, 2016 at 1:09 pm #1159485Nico
MemberYou are welcome Rodrigo!
I still am not clear on how I would know which post ids to use with wp_delete_post or which event metadata to delete.
For this you can use the get_posts function, passing ‘post_type’ => ‘tribe_events’. If you use wp_delete_posts then everything that is tied to it is deleted also. This includes comments, post meta fields, and relationships between the post and taxonomy terms. Just mentioned this because if you are going to delete and recreate hundreds of events daily orphan data in the database can grow fast! So make sure to do some tests making sure there’s no orphan data left behind.
Also not clear on performance issues. Can you say more? I would think that the less rows in the db the faster the performance which would argue for deleting past events all together once they are no longer needed.
By this I meant that for example running a loop to delete hundreds of events can crash the server, so you might want to do this in batches. So I was referring the performance of the clean up script no the site!
Please let me know if this helps,
Best,
NicoSeptember 6, 2016 at 12:30 pm #1160583Rodrigo Torres
ParticipantThank you!
September 6, 2016 at 2:04 pm #1160630Nico
MemberYou are welcome Rodrigo 🙂
As you marked my previous reply correct and as everything seems to be sorted out I’ll go ahead and close out this thread. If you need help with anything else please don’t hesitate to create a new thread and we will be happy to assist you.
Best,
Nico -
AuthorPosts
- The topic ‘How do I batch delete hundreds of Events?’ is closed to new replies.
