Why do I see all posts/products after filtering, sorting or using pagination on a category/term, author, or search archive page?
This happens when you are using a Listing Builder listing on a category/tag/term, author, or search achive page.
On category/term/tag, author, and search archive pages, FacetWP will automatically detect and use the native archive query. This means that on WP archives, the recommended approach is to just use the WP archive query itself, instead of creating a new query with the Listing Builder (or a custom WP_Query).
If you do add a Listing Builder listing on a WP archive, what happens is that before filtering, FacetWP uses the native query. And to generate the filtered results, it will use the Listing Builder listing query, which will get all posts/products.
To fix this difference, you have two options:
Option 1: Pre-filter Listing Builder listing templates for the query
The recommended way to solve this is to use the facetwp_template_use_archive filter. With this hook in place, FacetWP will automatically pre-filter the Listing Builder query based on the current category/tag/term, author, or search term(s), by injecting them into the query arguments during filtering.
Note that even with this hook in place the native archive query will still be used before filtering. This may lead to differences before and after filtering, caused by query arguments other than the current category/tag/term, author or search term(s), like posts_per_page, order and orderby. These differences can be fixed by manually bringing the native archive/search query arguments in line with the Listing Builder listing’s query arguments with a pre_get_posts filter. Or by forcing FacetWP to entirely ignore the archive query.
Option 2: Pre-filter results based on the archive page URI
Instead of pre-filtering the listing based on the archive query that the listing is on, with the facetwp_template_use_archive hook (option 1 above), you can also pre-filter the listing query based on the page URI of the archive page.
This can be done with a so-called dynamic URL tag. See this section in our tutorial on dynamic URL tags for how to do this exactly.
In general, for Listing Builder listings placed on archives, we recommend using the facetwp_template_use_archive hook, because it is only one line in your functions.php and works for all types of archives. Using a dynamic URL tag can be useful if you want to build complex queries in the Listing Builder, instead of customizing the native archive query with a pre_get_posts hook.