/facet/query_objects

DescriptionDescription

This filter is called before a facet queries object ids (post ids, term ids or user ids) from selected facet value(s).

It allows to override the behaviour of the native query_objects method of the facet and to pass custom object ids in order to change the filtered content.

ArgumentsArguments

ArgumentTypeDescription
$object_ids mixedArray of object IDs (false by default)
$facetarrayHolds facet settings

ExampleExample

PHP
functions.php
function prefix_query_objects( $object_ids, $facet ) {

	// If it matches facet id 1, we set a custom set of post ids.
	if ( 1 === $facet['id'] ) {
		$object_ids = [ 1, 20, 34, 105 ];
	}

	// If it matches facet id 2, we make a custom query from selected facet values.
	if ( 2 === $facet['id'] ) {
		$object_ids = my_custom_query( $facet['selected'] );
	}

	// Return false by default.
	return $object_ids;

}
add_filter( 'wp_grid_builder/facet/query_objects', 'prefix_query_objects', 10, 2 );