The filter hook below allows using a custom defined parameter events=active
to automatically filter results shown in shortcodes and listings module to only show events that are currently active/open.
Add the code below to filter_functions.php
in overrides, and then in your shortcode or listings module add events=open
in the custom parameters attribute or setting respectively.
Clickfwd\Hook\Filter::add('pre_get_listings_listings_module_query', function($listingsRepository, $params)
{
$customParams = $params['params']['module']['custom_params'] ?? '';
if (empty($customParams)) {
return $listingsRepository;
}
if (strpos($customParams, 'events=active') === false) {
return $listingsRepository;
}
// Start
$listingsRepository->where("jr_eventstart <= CURDATE()");
// End
$listingsRepository->where("jr_eventend >= CURDATE()");
return $listingsRepository;
});