feat(abilities): scope UpcomingCountAbilities by a filter taxonomy/term pair - #307
Merged
Conversation
…rm pair
Adds two optional inputs — filter_taxonomy + filter_term_id — to
data-machine-events/get-upcoming-counts. When both are provided, the
query additionally joins wp_term_relationships + wp_term_taxonomy to
require every counted post be ALSO tagged with the filter term in the
filter taxonomy.
This unlocks per-archive upcoming-events stats lines on the consuming
sites, e.g.:
- Artist archive: 'N upcoming events at N venues in N locations'
taxonomy=venue + filter_taxonomy=artist + filter_term_id=N
taxonomy=location + filter_taxonomy=artist + filter_term_id=N
- Location archive: 'N upcoming events at N venues'
taxonomy=venue + filter_taxonomy=location + filter_term_id=N
Backward-compat: when filter_taxonomy/filter_term_id are not provided,
the SQL is byte-identical to the pre-existing query. Existing callers
(VenueMapAbilities, calendar-stats consumers) keep working unchanged.
Misuse contract: providing only one of the filter pair returns
WP_Error('invalid_filter_pair') instead of silently falling back to the
unfiltered query — this surfaces wiring bugs immediately rather than
hiding them as 'no filter applied' results.
Refs Extra-Chill/extrachill-events#107.
Contributor
Homeboy Results —
|
This was referenced May 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs Extra-Chill/extrachill-events#107.
Summary
Extends
UpcomingCountAbilities::executeGetUpcomingCounts()with an optional co-occurrence filter pair so callers can count terms in one taxonomy scoped to events that are also tagged with a specific term in another taxonomy.This unlocks per-archive upcoming-events stats lines on the consuming sites, e.g.:
N upcoming events at N venues in N locationstaxonomy=venue + filter_taxonomy=artist + filter_term_id=Ntaxonomy=location + filter_taxonomy=artist + filter_term_id=NN upcoming events at N venuestaxonomy=venue + filter_taxonomy=location + filter_term_id=NNew input params
filter_taxonomyfilter_term_idsanitize_key()applied. Must be a registered taxonomy.filter_term_idfilter_taxonomyabsint()applied. Must be > 0.Both must be provided together. Misuse contract: providing only one returns
WP_Error('invalid_filter_pair')(HTTP 400) rather than silently falling back to the unfiltered query — wiring bugs surface immediately instead of hiding as 'no filter applied' results.A nonexistent
filter_taxonomyreturns the distinct codeinvalid_filter_taxonomyso callers can differentiate usage bugs from registration bugs.SQL extension
When both filter params are provided, the query gains two additional INNER JOINs scoped with
f_tr/f_ttaliases:All values flow through
$wpdb->prepare()— no interpolation of caller-supplied data. Table prefixes use$wpdb->term_relationships/$wpdb->term_taxonomy(multisite-safe).Backward-compatibility guarantee
When
filter_taxonomy/filter_term_idare not provided, the unfiltered SQL branch is byte-identical to the pre-existing query. Existing callers (VenueMapAbilities, calendar-stats consumers, etc.) keep working unchanged. No widening of the existing contract.The ability has no internal cache, so no cache-key updates were needed; consumers that wrap this ability with their own cache (e.g. extrachill-events follow-up PR) must include the new params in their key.
Before / after
Suppose Venue A has 2 upcoming events (both tagged Artist X), Venue B has 1 upcoming event (Artist X), Venue C has 1 upcoming event (Artist Y).
Unfiltered (existing behavior, unchanged):
Filtered to Artist X:
Tests
tests/Unit/UpcomingCountAbilitiesTest.phpcovers:success: true, total: 0, terms: [](not WP_Error, not unfiltered set).filter_taxonomyor onlyfilter_term_idreturnsWP_Error('invalid_filter_pair').WP_Error('invalid_filter_taxonomy').Mirrors the existing
VenueStatsAbilitiesTestdirect-execute pattern.Out of scope
new UpcomingCountAbilities()->executeGetUpcomingCounts(...), same pattern ascalendar-stats.php.mention <@532385681268408341> when ready for review