Skip to content

Commit

Permalink
Prevent duplicate post format taxonomy queries (WordPress#66627)
Browse files Browse the repository at this point in the history
Add an early return to gutenberg_add_format_query_vars_to_query_loop_block if the taxonomy query already includes post formats. 

Co-authored-by: carolinan <[email protected]>
Co-authored-by: Mamaduka <[email protected]>
Co-authored-by: david-binda <[email protected]>
  • Loading branch information
4 people authored Nov 1, 2024
1 parent fbdc0f9 commit 99d2275
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/compat/wordpress-6.7/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ function gutenberg_add_format_query_vars_to_query_loop_block( $query, $block ) {
return $query;
}

// Return early if the query already contains a post format. This is to avoid duplication if the
// WordPress core filter is already applied.
if ( ! empty( $query['tax_query'] ) ) {
foreach ( $query['tax_query'] as $taxquery ) {
if ( isset( $taxquery['taxonomy'] ) && 'post_format' === $taxquery['taxonomy'] ) {
return $query;
}
}
}

$formats = $block->context['query']['format'];
/*
* Validate that the format is either `standard` or a supported post format.
Expand Down

0 comments on commit 99d2275

Please sign in to comment.