From c971278a9ec2ed1dd1d72f4bbae14050c2ea3f5a Mon Sep 17 00:00:00 2001 From: goldenapples Date: Thu, 23 Jul 2026 09:18:46 -0400 Subject: [PATCH] Apply uniquified query ID to all blocks which inherit queryId The function which deduplicated query IDs on a page and passed that unique ID to the post template inside each query was causing other blocks in the query - pagination, query-filters, no posts message - to be mismatched with the posts displayed. This change should fix that issue by setting the same query ID on all blocks inside a query that should inherit the queryID. --- hm-query-loop.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/hm-query-loop.php b/hm-query-loop.php index 7c1f8da..3fa1656 100644 --- a/hm-query-loop.php +++ b/hm-query-loop.php @@ -244,10 +244,15 @@ function deduplicate_query_ids( $pre_render, $parsed_block ) { // for this specific query block, not nested ones. $depth = 0; - // Dynamically add a render_block_context filter to override queryId - // for any core/post-template blocks inside this query. - $context_filter = function ( $context, $inner_parsed_block ) use ( $unique_query_id ) { - if ( 'core/post-template' === $inner_parsed_block['blockName'] ) { + // Dynamically add a render_block_context filter to propagate the reassigned + // queryId to every descendant that inherited the original id — the + // post-template plus any sibling blocks that build query URLs from it + // (core/query-pagination, core/search, and the query-filter blocks). + // Match on the inherited queryId rather than the block name so a nested + // core/query, which provides its own queryId to its children, is left + // untouched. + $context_filter = function ( $context ) use ( $unique_query_id, $original_query_id ) { + if ( ( $context['queryId'] ?? null ) === $original_query_id ) { $context['queryId'] = $unique_query_id; } return $context;