To vote or comment, enter your email and we'll send a magic link
FacetWP is is not functioning properly in combination with SearchWP, when the main query for the search results page uses pre_get_posts() to filter out certain posts.
The retrieved posts on a search page DO reflect the filtered posts, also when using facets. But the Facets themselves (and their counts) act like the pre_get_posts() is not there.
For example I use pre_get_posts() to filter out Events (Custom post type Events) that are in the past, using a custom event date field. This works great for every query where this happens. It works with normal WP Search and with SearchWP.
But when using Facetwp facets on the search result page, the filters go wrong.
The cause is in Facetwp > integrations > searchwp > searchwp.php, where the original WP query is killed and a new fresh new \SWP_Query is created.
There is a workaround: to double all filtering done with pre_get_posts() in a searchWP hook: https://searchwp.com/documentation/hooks/searchwps-wp_query-args/
It works, but it would be great is the search wp integration just works and takes any adaptations to the search query into account.
I suspect this happens more often but is not noticed, because the retrieved posts themselves are correct, only the facets (and their counts) go wrong.