humanmade / humanmade/query-filter
Taxonomy filter dropdown ignores other active filters (shows terms with zero matching results)
- Dominant language
- JavaScript
- Stars
- 123
- Forks
- 33
- Avg merge
- 6h 7m
- Merged PRs (30d)
- 5
Description
## Summary
When a Query Loop has multiple `query-filter/taxonomy` blocks and one filter is already active, the *other* filter's dropdown still lists every term that has posts *anywhere on the site* — not just terms that have posts matching the currently active filter combination. This lets users pick a term that returns zero results.
## Steps to reproduce
1. Add two `query-filter/taxonomy` blocks to a `core/query` loop (e.g. `category` and a custom `country` taxonomy), in derived mode (no `includeTerms` set).
2. Visit the archive with one filter active via URL, e.g. `?query-category=some-category`.
3. Open the *other* filter's dropdown (e.g. country).
4. Note that it lists every country with posts in *any* category, including ones with zero posts in `some-category`. Selecting one of those returns "no results".
## Root cause
`get_filter_terms()` in `inc/namespace.php` resolves each dropdown's terms via a plain `get_terms( ['taxonomy' => ..., 'hide_empty' => true] )`. This only reflects whether a term has posts *at all*, and has no awareness of `$_GET` params for other active `query-filter/taxonomy` blocks on the same query. There's also no hook (`apply_filters`/`do_action`) anywhere in the plugin to intervene without forking it.
## Suggested fix
When other taxonomy filters are active on the same query (i.e. other `query-{taxonomy}` GET params matching the block's query context), scope the term list to only those with `object_ids` intersecting posts that also match the other active filters — e.g. via `get_terms(['object_ids' => $filtered_post_ids])` instead of a blanket `hide_empty`. Alternatively, exposing a filter hook around `get_filter_terms()`'s return value would let consumers implement this themselves.
Happy to help test a fix if useful — this is affecting a faceted News/Stories archive built on this plugin.
## Disclosure
This issue was drafted by AI and approved by me.
Contributor guide
Research direction
Start by reading get_filter_terms() in inc/namespace.php and reproduce the two-taxonomy query-filter scenario described in the issue. Trace how active query-{taxonomy} GET parameters affect the query context, then verify that the other dropdown excludes terms with no matching posts while preserving existing filtering behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 54/100