JReviews logo Docs
Menu
Version

pre_get_listings_listings_module_query

Filter the listings query.

Filter
Listings List

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;
});
Development & Support
Customizations are not included with support. We provide this information to make it easier for developers to extend the functionality. From time to time we may have some availability for custom work. Get in touch to see if there's an opportunity to work together.

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