Skip to content

Conversation

@ntsekouras
Copy link

@ntsekouras ntsekouras commented Dec 15, 2025

Trac ticket: https://core.trac.wordpress.org/ticket/64416

In GB we've updated the structure of Query Loop's taxQuery to also handle exclusion of terms in this PR (WordPress/gutenberg#73790).

The new structure is:

{
	query: {
		taxQuery: {
			include: {
				category: [1, 2, 3],
				post_tag: [10, 20]
			}
			exclude: {
				category: [5, 6],
				post_tag: [15]
			}
		}
	}
}

We need to update build_query_vars_from_query_block to handle this new taxQuery structure.

Testing instructions

Since this change should be handling Query Loop structure for 7.0 after the packages sync, we can test by:

  1. Create two posts and post category.
  2. Add the new post category to one of your posts.
  3. In one post (doesn't matter which) insert a custom Query Loop (through inspector controls) and add a taxonomy:category filter with your created category.
  4. In that post, switch to the code editor and add the below code for a Query Loop that includes the new taxQuery structure. Make sure to update the category id from the snippet, with the category id you've created. This refers to the "taxQuery":{"include":{"category":[3]}} part, where you should probably need to update the 3.
<!-- wp:query {"queryId":35,"query":{"perPage":2,"pages":0,"offset":0,"postType":"post","order":"desc","orderBy":"date","author":"","search":"","exclude":[],"sticky":"","inherit":false,"parents":[],"format":[],"taxQuery":{"include":{"category":[3]}}}} -->
<div class="wp-block-query"><!-- wp:post-template -->
<!-- wp:post-title /-->

<!-- wp:post-terms {"term":"category"} /-->

<!-- wp:post-terms {"term":"post_tag"} /-->

<!-- wp:post-date {"metadata":{"bindings":{"datetime":{"source":"core/post-data","args":{"field":"date"}}}}} /-->
<!-- /wp:post-template -->

<!-- wp:query-pagination -->
<!-- wp:query-pagination-previous /-->

<!-- wp:query-pagination-numbers /-->

<!-- wp:query-pagination-next /-->
<!-- /wp:query-pagination -->

<!-- wp:query-no-results -->
<!-- wp:paragraph {"placeholder":"Add text or blocks that will display when a query returns no results."} -->
<p></p>
<!-- /wp:paragraph -->
<!-- /wp:query-no-results --></div>
<!-- /wp:query -->
  1. Save the post
  2. Observe that in the editor the category filter should not work for the copied block (as the packages are not sync)
  3. Visit front end and observe that the results are filtered properly based on the category for both blocks (old structure and the upcoming new structure).

This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@github-actions
Copy link

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@ntsekouras ntsekouras marked this pull request as ready for review December 15, 2025 08:51
@github-actions
Copy link

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props ntsekouras.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Comment on lines +2753 to +2758
$exclude_terms = isset( $tax_query_input['exclude'] ) && is_array( $tax_query_input['exclude'] )
? $tax_query_input['exclude']
: array();
$include_terms = isset( $tax_query_input['include'] ) && is_array( $tax_query_input['include'] )
? $tax_query_input['include']
: array();
Copy link
Member

Choose a reason for hiding this comment

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

Indentation doesn't seem quite right:

Suggested change
$exclude_terms = isset( $tax_query_input['exclude'] ) && is_array( $tax_query_input['exclude'] )
? $tax_query_input['exclude']
: array();
$include_terms = isset( $tax_query_input['include'] ) && is_array( $tax_query_input['include'] )
? $tax_query_input['include']
: array();
$exclude_terms = isset( $tax_query_input['exclude'] ) && is_array( $tax_query_input['exclude'] )
? $tax_query_input['exclude']
: array();
$include_terms = isset( $tax_query_input['include'] ) && is_array( $tax_query_input['include'] )
? $tax_query_input['include']
: array();

$tax_query = array();
// If there are keys other than include/exclude, it's the old
// format e.g. "taxQuery":{"category":[4]}
if ( ! empty( array_diff( array_keys( $tax_query_input ), array( 'include', 'exclude' ) ) ) ) {
Copy link
Member

Choose a reason for hiding this comment

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

Technically someone could have a taxonomy named include or exclude, no?

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.

2 participants