I’m trying to get SearchWP to work with Bricks search filter on the WooCommerce archive pages. I’ve tried using the Bricks search filter with both the Product element and a custom query loop. But the results are not correct. SearchWP is supposed to be a drop-in replacement. It works with the ajax search widget we added in the header but not the archive page search results. FacetWP has you add a custom query variable, do I need to do something like that?
I’ve got it works with FacetWP and selected SearchWP as the source for search in the search facet.
I had to add these snippets to get it to work with the bricks products element.
/**
* Activate FacetWP on brick products block
*/
add_filter( 'bricks/posts/query_vars', function( $query_vars, $settings, $element_id ) {
if ( $element_id === '641c6c' ) { // change value to your Products element's unique element ID
$query_vars['facetwp'] = true;
}
return $query_vars;
}, 10, 3 );
add_filter( 'facetwp_is_main_query', function( $is_main_query, $query ) {
if ( $query->is_archive() && $query->is_main_query() ) {
$is_main_query = false;
}
return $is_main_query;
}, 10, 2 );
// Temporary patch for Facetwp + bricks integration
add_action('init', function() {
remove_action( 'bricks/archive_product/before', [Bricks\Theme::instance()->woocommerce, 'setup_query'], 10,2 );
});
The one thing I can’t figure out is the custom order sort. I want to default to popularity in bricks, but that breaks the SearchWP relevance and custom order. Any ideas how to override the bricks search sort when a search term is present?