wordpress-develop
wordpress-develop copied to clipboard
Update `build_query_vars_from_query_block` to handle new `taxQuery` structure
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:
- Create two posts and post category.
- Add the new post category to one of your posts.
- In one post (doesn't matter which) insert a custom
Query Loop(through inspector controls) and add ataxonomy:categoryfilter with your created category. - In that post, switch to the code editor and add the below code for a Query Loop that includes the new
taxQuerystructure. Make sure to update thecategory idfrom 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 the3.
<!-- 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 -->
- Save the post
- Observe that in the editor the category filter should not work for the copied block (as the packages are not sync)
- 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.