Skip to content

fix/4193: Fix meta facet counts for late-rendered facet-meta blocks#4284

Open
Sidsector9 wants to merge 4 commits intodevelopfrom
fix/4193
Open

fix/4193: Fix meta facet counts for late-rendered facet-meta blocks#4284
Sidsector9 wants to merge 4 commits intodevelopfrom
fix/4193

Conversation

@Sidsector9
Copy link
Member

@Sidsector9 Sidsector9 commented Feb 18, 2026

Description of the Change

What was the issue?

The meta facet aggregations were built during the main facetable query, based on facet fields discovered early. When elasticpress/facet-meta is rendered later at runtime (for example via do_blocks()), the main query has already completed. In that case, the requested meta field is missing from the original aggregation request, so that facet receives no counts and terms render as disabled/empty.

How does this fix work?

This PR adds a runtime-safe fallback for meta facet aggregations:

  • Adds the get_facet_aggregation_for_field() in the meta facet type.
  • If the aggregation for the requested meta field is missing, it runs a scoped facetable fallback query for that field in the current query context.
  • It merges the returned aggregation back into the original query’s facet aggregations.
  • Updates the meta facet renderer to use this method instead of directly reading aggregation data.
  • This allows late-rendered meta facet blocks to display correct counts and clickable terms.

Closes #4193

How to test the Change

Replace hero_caption from the following with a meta value that is relevant to your site, and add it to your functions.php file:

add_action( 'wp_footer', function() {
	if ( ! is_archive() ) {
		return;
	}
	echo do_blocks( '<!-- wp:elasticpress/facet-meta {"displayCount":true,"facet":"hero_caption"} /-->' );
} );

On develop, it will display the the list, but the counts will be 0, making the list items not clickable. Switch to the fix branch and observe that it displays the count, and the items are clickable.

Changelog Entry

Fixed - Bug fix

Credits

Props @burhandodhy @Sidsector9

Checklist:

@Sidsector9 Sidsector9 requested review from burhandodhy and felipeelia and removed request for burhandodhy February 18, 2026 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: Meta filter block isn’t working when added via code.

1 participant