Launch Sale: 20% off all plugins. Limited time only.

Developer hooks

Refinery Search has filters and actions for changing what is searched and shown, and theme templates for the results page. Add hooks in a child theme’s functions.php file or in a small custom plugin, so they survive theme and plugin updates. After changing what goes into the search data, click Rebuild now under Refinery > Search > Settings > Speed.

Filters that run while a shopper searches (refinery_search_query_words, refinery_search_rows, refinery_search_suggestions and refinery_search_text_matches) are also used by fast server search, which answers before the theme and most plugins load. Add those in a must-use plugin (a PHP file in wp-content/mu-plugins) so they apply to every search, or turn off Fast server search under Settings > Speed.

Filters

FilterArgumentsPurpose
refinery_search_post_types$typesPost types in the search data (post type => product or post)
refinery_search_product_row$row, $productA product’s search data before it is saved: add words (words), exact tokens (exact) or badges (badges)
refinery_search_post_row$row, $postAn article’s search data before it is saved
refinery_search_query_words$words, $term, $typeSearch words before matching; a word may become a list of alternatives
refinery_search_rows$rows, $words, $term, $typeMatched rows, best first, before they are cut to the limit
refinery_search_suggestions$out, $termServer suggestions before they are sent
refinery_search_text_matches$fill, $term, $typeReturn false to stop filling suggestions with items that mention the words only in their description or content
refinery_search_file_data$data, $langThe browser product list before it is written; extras go under x
refinery_search_script_config$configSettings passed to the search script
refinery_search_load_assets$loadWhether the search script loads on the current page
refinery_search_results_tabs$tabsResults page tabs (tab => post type)
refinery_search_keep_score$keepWhether a learned score survives re-indexing
refinery_search_languages$languagesThe store’s languages, for multilingual plugins other than WPML and Polylang
refinery_search_post_language$code, $postA post’s language
refinery_search_current_language$codeThe language of the current request
refinery_search_events_per_minute$limitMost searches recorded per minute, site-wide (600 by default)

Actions

refinery_search_before_results, refinery_search_results_notices (under the heading and search field), refinery_search_after_results and refinery_search_no_results ($results) run on the results page. refinery_search_build_finished ($build) runs when a full rebuild of the search data finishes.

Example: search a custom field

This adds a product’s brand, stored in the custom field _brand, to the words it can be found by:

add_filter( 'refinery_search_product_row', function ( $row, $product ) {
	$brand = (string) $product->get_meta( '_brand' );
	if ( '' !== $brand ) {
		$row['words'][] = $brand;
	}
	return $row;
}, 10, 2 );

Browser search extensions

The search script exposes window.refinerySearchCore with addFilter( name, callback ) for the filters queryWords, rank and parseFile, which mirror the server filters above. Load the extension script with refinery-search as a dependency.

Templates

Copy templates/results.php (the results) or templates/search-results.php (the whole page) to a refinery-search/ folder in the theme. See Results page.

Grow Your Store Smarter

One email a week with plugin updates, revenue tactics, and strategies top WooCommerce stores use to scale.

By subscribing, you agree to receive emails from Refinery and to our Privacy Policy. Unsubscribe anytime.

Item added to cart.
0 items - $0.00