Customize Instant Search Options.
Parameters
- $options
array
Array of parameters used in Instant Search queries.
Changelog
- Introduced in Jetpack 7.7.0
How to use this hook
Notes
You can use this filter to customize all search queries used in Jetpack’s Search. In the example below, we will filter all search queries so that only results from products and pages are shown. This does not impact the number of records that are indexed though.function jp_filter_query( $options ) { $options['adminQueryFilter'] = array( 'bool' => array( 'should' => array( array( 'term' => array( 'post_type' => product' ) ), array( 'term' => array( 'post_type' => page ) ), ) ) ); return $options; } add_filter( 'jetpack_instant_search_options', 'jp_filter_query' );One could also use that filter to remove all posts/pages with a certain category, like so:
function jp_filter_query( $options ) { $options['adminQueryFilter'] = array( 'bool' => array( 'must_not' => array( array( 'term' => array( category.slug' => 'removeme' ) ), ) ) ); return $options; } add_filter( 'jetpack_instant_search_options', 'jp_filter_query' );You can check our ElasticSearch documentation to find out more about the other fields you could use to customize queries.