wordpress-develop icon indicating copy to clipboard operation
wordpress-develop copied to clipboard

Update `build_query_vars_from_query_block` to handle new `taxQuery` structure

Open ntsekouras opened this issue 1 month ago • 3 comments

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 (https://github.com/WordPress/gutenberg/pull/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.

ntsekouras avatar Dec 15 '25 07:12 ntsekouras