pre_get_listings_listings_module_query
Filter the listings query.
You need to have a working knowledge of Hooks before you get started.
Parameters
Name | Type | Description |
---|---|---|
$listingsRepository |
parameter |
(ListingsRepositoryComponent) |
$params |
parameter |
(array) associative array with contextual data |
Boilerplate Code
Use the boilerplate code to start using the filter, and add your own logic to modify the first argument and return it.
Clickfwd\Hook\Filter::add('pre_get_listings_listings_module_query', function($listingsRepository, $params)
{
// Uncomment line below to view available data passed into hook
// fwd_dd($listingsRepository, $params);
return $listingsRepository;
});
Examples
Using a custom parameter to filter results for active events
This filter allows using a custom defined parameter `events=active` to automatically filter results shown in shortcodes and listings modules/widgets to only show events that are currently active/open.
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;
});
Source Files
/controllers/modules/module_listings_controller.php