Modern Tribe’s Event Calendar is likely the most popular calendar plugin available for WordPress. I’ve talked about querying events using WP_Query in a previous post but that’s applicable to both the free and premium versions.

Programmatically Create Recurring Events with Event Calendar Pro

The premium version offers a lot of great features, but if you’re looking to programmatically manipulate the calendar, it’s a little more difficult to work with it.

  • there isn’t clear documentation on how to take advantage of certain features from a developer’s perspective
  • the places where people have asked how to do so occasionally leave something to be desired.

Case in point: When we need to programmatically create recurring events.

Programmatically Create Recurring Events

To be fair, I think the plugin is for users versus developers and so providing documentation on how to leverage some aspect of its internal code isn’t an obligation on their part.

Secondly, it’s open source. So for those of us who have a need to invoke some of its code, have the time, and a debugger handy, it’s not terribly difficult to sit down and see how it works.

The advantage of open source, right?

With that said, the way to programmatically create recurring events with Event Calendar requires that we use the Tribe__Events__Pro__Recurrence__Meta class.

This assumes that you’re using the latest version of the plugin (as the time of this post) and that you’re familiar with the queuing mechanism that’s built into the plugin. I’ll cover this more after the code below.

To create a recurring event, the most basic things you need are:

  • the type of recurring event,
  • how it will end,
  • the start date,
  • the end date.

The rest can be a series of default values. Then it’s a matter of grabbing an instance to a class, setting the values, and calling a method.

For example:

Notice the first parameter to the updateRecurrenceMeta function assumes you have the ID of an event (which is retrieved when you first create an event).

Secondly, depending on the number of events you’re working on, it may take a few minutes for all of them to be created in the database. This is because of the way the plugin queues up a series of events.

Rather than creating them all at once, it will serialize the events and then create them in batches. This is a smart way to handle it. And if you’re looking to take advantage of it programmatically, this is a way to get all of that functionality for free.