Skip to content

Instantly share code, notes, and snippets.

@jreviews
Last active October 26, 2021 14:19
Show Gist options
  • Save jreviews/7d47597c1b079fff615bbf1e08eadace to your computer and use it in GitHub Desktop.
Save jreviews/7d47597c1b079fff615bbf1e08eadace to your computer and use it in GitHub Desktop.
Using a custom parameter to filter results for active events

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;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment