How do I batch delete hundreds of Events?

Home Forums Calendar Products Events Calendar PRO How do I batch delete hundreds of Events?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1158454
    Rodrigo Torres
    Participant

    Hi, 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!
    Rodrigo

    #1158506
    Nico
    Member

    Hi 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,
    Nico

    #1158980
    Rodrigo Torres
    Participant

    Thanks! 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.

    #1159485
    Nico
    Member

    You 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,
    Nico

    #1160583
    Rodrigo Torres
    Participant

    Thank you!

    #1160630
    Nico
    Member

    You 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

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘How do I batch delete hundreds of Events?’ is closed to new replies.