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
Argument | Type | Description |
$object_ids | mixed | Array of object IDs (false by default) |
$facet | array | Holds 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 );