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
| Filter | Arguments | Purpose |
|---|---|---|
refinery_search_post_types | $types | Post types in the search data (post type => product or post) |
refinery_search_product_row | $row, $product | A product’s search data before it is saved: add words (words), exact tokens (exact) or badges (badges) |
refinery_search_post_row | $row, $post | An article’s search data before it is saved |
refinery_search_query_words | $words, $term, $type | Search words before matching; a word may become a list of alternatives |
refinery_search_rows | $rows, $words, $term, $type | Matched rows, best first, before they are cut to the limit |
refinery_search_suggestions | $out, $term | Server suggestions before they are sent |
refinery_search_text_matches | $fill, $term, $type | Return false to stop filling suggestions with items that mention the words only in their description or content |
refinery_search_file_data | $data, $lang | The browser product list before it is written; extras go under x |
refinery_search_script_config | $config | Settings passed to the search script |
refinery_search_load_assets | $load | Whether the search script loads on the current page |
refinery_search_results_tabs | $tabs | Results page tabs (tab => post type) |
refinery_search_keep_score | $keep | Whether a learned score survives re-indexing |
refinery_search_languages | $languages | The store’s languages, for multilingual plugins other than WPML and Polylang |
refinery_search_post_language | $code, $post | A post’s language |
refinery_search_current_language | $code | The language of the current request |
refinery_search_events_per_minute | $limit | Most 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.