apply_filters ( 'jetpack_instant_search_options', array $options )

Customize Instant Search Options.

Source file: modules/search/class-jetpack-instant-search.php

View in GitHub

Parameters

$options

(array) Array of parameters used in Instant Search queries.


Changelog

Since: Jetpack 7.7.0


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.

Have a note to contribute?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s