Closed xmedia-nl closed 9 months ago
Found it! Weighting was disabled. I noticed the built-in widget did filter correctly, so I compared the query args and saw the weighting was missing on my custom query. For reference, this filter needed to return true: ep_enable_do_weighting
add_filter('ep_enable_do_weighting', [$this,'set_weighting'], 999, 4);
public static function set_weighting($should_do_weighting, $weight_config, $args, $formatted_args)
{
if (isset($args['custom_es_search'])) {
return true;
}
return $should_do_weighting;
}
closed
Describe your question
I made a custom searchpage that does a WP Query with the searchkeyword. On the searchpage I generate a few filters. I haven't used the default widgets because that makes the searchpage terribly slow. So what I did was read the ep_facet_aggs from the globals and use the product_cat, ep_meta_range_filterprice_min, ep_meta_range_filterprice_max and pa_merk (which is the product brand). Then I make a general WP Query with the keyword and posttype and add facets with the ep_facet_query_filters hook
Problem is that the ep_facet_aggs gives a count for that brand, but when adding the filter for that brand, the results don't always match the count. For instance, brand Hills says count is 7, but when adding this to the filter there are 0 results. Most brands do give the correct numbers of results, so the filter does work as intended. Can someone spot what I can improve to get the correct results?
The actual search can be tested here: https://landvandieren.nl/?s=kattenvoer
When a brand is selected, the filters look like this after the hook is processed
Code of Conduct