DescriptionDescription
This filter is called before WP_Query
, WP_Term_Query
or WP_User_Query
is ran from the indexer.
It allows to modifies query arguments of the current facet to index. When a facet is indexed, the indexer retrieves at first all post/term/user IDs matching the facet. This filter allows to modify which object ids to retrieve.
ArgumentsArguments
Argument | Type | Description |
$query_args | array | Holds indexer query args |
$object_type | string | Current object type to index (post, term or user) |
$facet | array | Holds facet settings |
ExampleExample
PHP
functions.php
function prefix_indexer_query_args( $query_args, $object_type, $facet ) {
// We exclude post IDs from indexer for Facet ID is equal to 1.
if ( 1 === $facet['id'] ) {
$query_args['post__not_in'] = [ 1, 2, 3, 4 ];
}
// We only index published posts (by default it indexes any post status).
if ( 'post' === $object_type ) {
$query_args['post_status'] = 'publish';
}
return $query_args;
}
add_filter( 'wp_grid_builder/indexer/query_args', 'prefix_indexer_query_args', 10, 3 );