close
Skip to content

Terms Query inspector controls revamp + add subterms option#71633

Merged
mikachan merged 26 commits intoWordPress:trunkfrom
kmanijak:add/terms-query-inspector-controls-revamp
Sep 19, 2025
Merged

Terms Query inspector controls revamp + add subterms option#71633
mikachan merged 26 commits intoWordPress:trunkfrom
kmanijak:add/terms-query-inspector-controls-revamp

Conversation

@kmanijak
Copy link
Copy Markdown
Contributor

What?

Closes

  1. Split Terms Query Inspector Controls into separate, more manageable files
  2. Introduce new attribute termToShow for high-level, predefined set of "filters"
  3. Restructure the options so they're less entangles and dependant on each other into more hierarchical approach
  4. Add "Subterms only" option automatically displaying subterms of currently viewed taxonomy archive

Why?

Subterms option is highly demanded. It should be easy to include Terms Query into taxonomy template and have it automatically display subterms of currently viewed taxonomy term.

This dictated restructure so there's no conflict between "Show only top level" vs "Show hierarchial", etc.

How?

New Inspector Controls logic is as follows with "Terms to Show" being radio button so options are mutually exclusive which removes the confusion where we had options conflicting with each other:

image

Examples:

Case Example Inspector Controls
Non-hierarchical taxonomy Tags on Category archive image
Hierarchical taxonomy on page - "All terms" Category on page image
Hierarchical taxonomy on page - other option Category on page - show hierarchy not displayed image
Hierarchical taxonomy on its archive - "All terms" Category on Category Archives image
Hierarchical taxonomy on its archive - other option Category on Category Archives - show hierarchy not displayed image

And it works fine with custom taxonomies like Product Categories from WooCommerce, showing subcategories in Products by Category page:

Categories hierarchy Editor Frontend
See Books & Toys direct children image image image

Testing Instructions

  1. Ensure experimental blocks are enabled.

Not taxonomy archive template

  1. Insert Terms Query in post
  2. Choose Tags as taxonomy
  3. Expected: There's only "All terms" option available
  4. Choose Category as taxonomy
  5. Expected:
    • There's "All terms" and "Show top level only" options available
    • "All terms" chosen as default
    • "Show hierarchy" is available
  6. Change to "Show top level only"
  7. Expected: Change is reflected in query and "Show hierarchy" disappeared

Taxonomy archive template

  1. Go to Category Archives template
  2. Insert Terms Query
  3. Expected:
    • There's "All terms", "Show top level only" and "Show subterms only" options available
    • "All terms" chosen as default
    • "Show hierarchy" is available
  4. Change to "Show subterms only"
  5. Expected: Change is reflected in query (we cannot determine in editor what to show exactly so I decided to display any subterms - the opposite of top level) and "Show hierarchy" disappeared
  6. Save and go to category page on the frontend
  7. Expected: Only subcategories of category you visit are displayed

Other

  1. Play around and change the setting to see if they default to correct values etc.

Testing Instructions for Keyboard

Screenshots or screencast

Before After

@github-actions
Copy link
Copy Markdown

github-actions bot commented Sep 12, 2025

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.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: kmanijak <karolmanijak@git.wordpress.org>
Co-authored-by: mikachan <mikachan@git.wordpress.org>
Co-authored-by: Marc-pi <mdxfr@git.wordpress.org>

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

@Marc-pi
Copy link
Copy Markdown

Marc-pi commented Sep 12, 2025

@kmanijak awesome :-) that's the exact need. kudos

Copy link
Copy Markdown
Member

@mikachan mikachan left a comment

Choose a reason for hiding this comment

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

I've left some minor comments, but otherwise this is looking good. Thanks so much for working on it, it's a great refactor!

I'll give this another test once it's been rebased after #71656 being merged.

Comment thread packages/block-library/src/term-template/index.php Outdated
Comment thread packages/block-library/src/term-template/index.php Outdated
Comment thread packages/block-library/src/terms-query/inspector-controls/max-terms-controls.js Outdated
Comment thread packages/block-library/src/term-template/index.php Outdated
@kmanijak
Copy link
Copy Markdown
Contributor Author

Thanks for initial review @mikachan! Conflict has been resolved and also I addressed your comments, it's ready for another round of review! 🙌

@kmanijak kmanijak requested a review from mikachan September 17, 2025 12:44
Copy link
Copy Markdown
Member

@mikachan mikachan left a comment

Choose a reason for hiding this comment

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

This is testing as expected following the testing instructions 🎉

  • Non-taxonomy archive template ✅
  • Taxonomy archive template ✅
  • Played around and changed the settings to see if they default to correct values ✅

I've left one more inline comment, but otherwise I think this is good to bring in ✨

Comment thread packages/block-library/src/terms-query/inspector-controls/max-terms-controls.js Outdated
Comment thread packages/block-library/src/terms-query/inspector-controls/max-terms-controls.js Outdated
Copy link
Copy Markdown
Member

@mikachan mikachan left a comment

Choose a reason for hiding this comment

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

I've noticed a potential bug when using the "Show hierarchy" option in a post. It looks like the subterms are duplicated below the main query on the front end, but they display as expected in the editor:

Editor Front end
image image

@kmanijak
Copy link
Copy Markdown
Contributor Author

I've noticed a potential bug when using the "Show hierarchy" option in a post. It looks like the subterms are duplicated below the main query on the front end, but they display as expected in the editor:

@mikachan, thank you for spotting it! Eventually it's a oneliner fix but took me a moment to spot a problem 😅 734b35a. I didn't set parent properly, as I didn't realise the children terms are fetched separately in render_block_core_term_template_get_children. I think we could optimise it and avoid additional queries and just build the structure ourselves after one query. But I don't think it's immediate need.

Copy link
Copy Markdown
Member

@mikachan mikachan left a comment

Choose a reason for hiding this comment

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

Looks like that fixes it!

I think we could optimise it and avoid additional queries and just build the structure ourselves after one query. But I don't think it's immediate need.

Yep, sounds like a good follow-up.

Comment thread packages/block-library/src/term-template/index.php Outdated
@mikachan mikachan merged commit 0824ebc into WordPress:trunk Sep 19, 2025
69 checks passed
@github-actions github-actions bot added this to the Gutenberg 21.8 milestone Sep 19, 2025
adamsilverstein pushed a commit to adamsilverstein/gutenberg that referenced this pull request Sep 22, 2025
…s#71633)

* Split controls into separate files

* Add subterms control

* Extract Empty Terms control

* Change the default parent to false

* Extract hierarchy control and make it render conditionally

* Make the terms to show a radio

* Modify the query depends on high level filters

* Default to all terms when changing some attributes

* Pass terms to show via context

* Filter only children terms when subtree is chosen

* Assign default query for subterms option

* Add explanation to subterms option

* Add a guard if terms is null

* Add support for subtree on the frontend

* Fix lint

* Fix merge conflicts

* Make code more defensive

* Simplify the condition

* Add end dot to comment

* Fix lint

* Rename function to match file name

* Rename MaxTermsControls to MaxTermsControl to make it consistent with the rest of inspector controls

* Fix duplicated taxonomies when showing all and hierarchical

* Fix lint

Co-authored-by: kmanijak <karolmanijak@git.wordpress.org>
Co-authored-by: mikachan <mikachan@git.wordpress.org>
Co-authored-by: Marc-pi <mdxfr@git.wordpress.org>
adamsilverstein pushed a commit to adamsilverstein/gutenberg that referenced this pull request Sep 22, 2025
…s#71633)

* Split controls into separate files

* Add subterms control

* Extract Empty Terms control

* Change the default parent to false

* Extract hierarchy control and make it render conditionally

* Make the terms to show a radio

* Modify the query depends on high level filters

* Default to all terms when changing some attributes

* Pass terms to show via context

* Filter only children terms when subtree is chosen

* Assign default query for subterms option

* Add explanation to subterms option

* Add a guard if terms is null

* Add support for subtree on the frontend

* Fix lint

* Fix merge conflicts

* Make code more defensive

* Simplify the condition

* Add end dot to comment

* Fix lint

* Rename function to match file name

* Rename MaxTermsControls to MaxTermsControl to make it consistent with the rest of inspector controls

* Fix duplicated taxonomies when showing all and hierarchical

* Fix lint

Co-authored-by: kmanijak <karolmanijak@git.wordpress.org>
Co-authored-by: mikachan <mikachan@git.wordpress.org>
Co-authored-by: Marc-pi <mdxfr@git.wordpress.org>
@mikachan mikachan mentioned this pull request Sep 25, 2025
15 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Block] Terms Query Affects the Terms Query Block [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants