Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Backporting latest changes from WordPress/gutenberg#39970.
  • Loading branch information
hellofromtonya committed Apr 4, 2022
commit e51fd0c51ea297bbc717cb42b344b956d0f3f8b4
11 changes: 4 additions & 7 deletions src/wp-includes/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -1132,14 +1132,14 @@ function build_query_vars_from_query_block( $block, $page ) {
if ( ! empty( $block->context['query']['categoryIds'] ) ) {
$tax_query[] = array(
'taxonomy' => 'category',
'terms' => $block->context['query']['categoryIds'],
'terms' => array_filter( array_map( 'intval', $block->context['query']['categoryIds'] ) ),
'include_children' => false,
);
}
if ( ! empty( $block->context['query']['tagIds'] ) ) {
$tax_query[] = array(
'taxonomy' => 'post_tag',
'terms' => $block->context['query']['tagIds'],
'terms' => array_filter( array_map( 'intval', $block->context['query']['tagIds'] ) ),
'include_children' => false,
);
}
Expand All @@ -1148,13 +1148,10 @@ function build_query_vars_from_query_block( $block, $page ) {
if ( ! empty( $block->context['query']['taxQuery'] ) ) {
$query['tax_query'] = array();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like it will stomp on any categories and tags in the shim above if the query block has both a legacy value and taxQuery defined.

Copy link

@ntsekouras ntsekouras Apr 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it will be possible to have the old and new attributes, as there is the client parsing that migrates the block. So in the case of deprecated blocks, we just fill the new attribute from the old ones.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if it will be possible to have the old and new attributes, as there is the client parsing that migrates the block.

Thanks, I gather that will come in as part of a package.

Copy link
Contributor

@adamziel adamziel Apr 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using an else if instead of an if would make this explicit for the future readers of this code. I'm thinking:

else if ( ! empty( $block->context['query']['taxQuery'] ) ) {

Not a blocker for the backport, though.

foreach ( $block->context['query']['taxQuery'] as $taxonomy => $terms ) {
if ( ! empty( $terms ) ) {
$term_ids = array_map( 'intval', $terms );
$term_ids = array_filter( $term_ids );

if ( is_taxonomy_viewable( $taxonomy ) && ! empty( $terms ) ) {
$query['tax_query'][] = array(
'taxonomy' => $taxonomy,
'terms' => $terms,
'terms' => array_filter( array_map( 'intval', $terms ) ),
'include_children' => false,
);
}
Expand Down