Published on Nov 6, 2022
Dynamic Data Condition For Checking Upcoming Events with The Events Calendar
Sridhar Katakam
In the Oxygen Facebook group, a user wanted to know how to conditionally output a Section if there is at least 1 future/upcoming event when using Modern Tribe’s The Events Calendar.
We can define a custom function that returns 1 if there are any upcoming events or 0 if there are none using tribe_get_events()
and use this with the Dynamic Data condition.
Add this in a custom functionality plugin or a code snippets plugin:
function wpdd_check_upcoming_events() {
return tribe_get_events( array( 'ends_after' => 'now') ) ? 1 : 0;
}
Then use it in the Oxygen editor like this:
Add a Dynamic Data condition → PHP Function Return value.
Function Name: wpdd_check_upcoming_events
Click INSERT.
Reference
https://theeventscalendar.com/knowledgebase/k/using-tribe_get_events/