If you’re not familiar with The Events Calendar Pro from Modern Tribe, it’s amazing and part of standard install when building a WordPress site.
One of the things that I see a lot of people asking about is how to programmatically control the events page.
The default behavior is that all published events appear on the calendar which brings up the question of what if you want to selectively control which events are visible.
It turns out to be pretty simple thanks to the pre_get_posts action.
All you need is a little bit of code in you functions.php.
Let’s break down the above.
The first two
if statements ensure that we’re only modifying the query when displaying the Events calendar.
For this example, we’re saying that we have an event category called Hidden
We modify the query to only display events that are
NOT IN the Hidden category.
It’d be just as easy to only display events that do belong to a certain category (or multiple categories).
From there, the sky’s the limit. It’s that simple!