Support Home > Appearance > Customize Search

Customize Search

Search Filters in action on a WooCommerce site.

Like the other Jetpack modules, the Search module includes filters allowing you to customize how Search works and is displayed.

The code snippets below provide examples of some of the filters included in the module. You can add these code snippets to a functionality plugin, or to your theme’s functions.php file.

You can also check Jetpack’s source code to discover more filters.

Please note that these snippets are provided as a convenience and our support team does not offer assistance on customizing them further.

In order for these filters to appear, you must add the “Search Filters (Jetpack)” widget to your sidebar or other widget area.

Add faceting widgets to the sidebar for post search

In order to enable faceted search on your search results page the widgets need to be enabled with code. Here is a simple example:

function jp_search_setup_filters() {
	if ( class_exists( 'Jetpack_Search' ) ) {
		Jetpack_Search::instance()->set_filters(array(
			'Categories' => array(
				'type'     => 'taxonomy',
				'taxonomy' => 'category',
				'count'    => 10,
			),
			'Tags' => array(
				'type'     => 'taxonomy',
				'taxonomy' => 'post_tag',
				'count'    => 10,
			),
			'Month' => array(
				'type'     => 'date_histogram',
				'field'    => 'post_date',
				'interval' => 'month',
				'count'    => 10,
			),
		) );
	} else {
		error_log("Jetpack search does not exist");
	}
}

add_action( 'init', 'jp_search_setup_filters' );

Add WooCommerce product faceting to the sidebar

For faceted search of WooCommerce products we can do something similar to the other faceting example:

function woo_search_setup_filters() {
	if ( class_exists( 'Jetpack_Search' ) ) {
		Jetpack_Search::instance()->set_filters(array(
			'Categories' => array(
				'type'     => 'taxonomy',
				'taxonomy' => 'product_cat',
				'count'    => 10,
			),
		) );
	} else {
		error_log("Jetpack search does not exist");
	}
}

add_action( 'init', 'woo_search_setup_filters' );

 

  • Table Of Contents

  • Categories

  • Contact Us

    Need more help? Feel free to contact us.