Skip to content

Conversation

@cr0ybot
Copy link
Contributor

@cr0ybot cr0ybot commented Oct 7, 2025

What?

Addresses a request to split #71916 further as a smaller PR.

This PR greatly simplifies the query and display of terms by removing hierarchical layouts in favor of a flat list in preparation for further block nesting and inheritance. It also removes a redundant attribute and reorganizes the edit component into its own folder, and controls have been refactored to have a single responsibility.

Why?

I've opened a string of PRs that have been too large and complex, starting with an attempt at adding a pattern/variation picker in which I suggested that the hierarchical rendering was causing more problems than it solved, and we already have a Term List block. In the PR attempting to address nesting and inheritance, I was asked to split it further.

How?

  1. Edit component and inspector controls moved into the "edit" folder.
  2. Nested rendering removed in favor of rendering a flat list.
  3. Removes the "terms to show" control and termsToShow attribute in favor of handling the same functionality with the termQuery attribute/context.

Testing Instructions

The block(s) should function the same as before, however the "Show subterms only" setting has been relocated to "Inherit parent term from taxonomy archive" without backwards-compatibility with the removed termsToShow attribute.

Some notable test cases:

  1. The "Include nested terms" option should display all terms as a flat list, regardless of parent/child relationships. This option is only available if a hierarchical taxonomy is selected.
  2. The "Inherit parent term from archive" control is displayed only on hierarchical taxonomy archive templates, and when active should display only children of the current queried term. This is only apparent on the front end in this PR.
  3. The above controls are mutually exclusive and are hidden/shown based on their relationship. Hierarchical is not supported when parent is set (when inheriting).

Screenshots or screencast

Before After
488861617-f938e86f-3346-4bd4-bd0c-e4e26de8a2a1 Screenshot 2025-10-07 at 9 40 10 AM

@github-actions
Copy link

github-actions bot commented Oct 7, 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: cr0ybot <[email protected]>
Co-authored-by: ntsekouras <[email protected]>

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

# Conflicts:
#	docs/reference-guides/core-blocks.md
#	packages/block-library/src/term-template/block.json
#	packages/block-library/src/term-template/index.php
#	packages/block-library/src/terms-query/block.json
#	packages/block-library/src/terms-query/edit.js
#	packages/block-library/src/terms-query/edit/index.js
#	packages/block-library/src/terms-query/inspector-controls/display-options.js
@cr0ybot cr0ybot mentioned this pull request Oct 7, 2025
15 tasks
@cr0ybot
Copy link
Contributor Author

cr0ybot commented Oct 7, 2025

Tagging @mikachan, @t-hamano, and @ntsekouras for review since I can't request reviewers.

@mikachan mikachan added [Type] Enhancement A suggestion for improvement. [Block] Terms Query Affects the Terms Query Block labels Oct 7, 2025
@ntsekouras
Copy link
Contributor

This leads to situations like this, which I've made consistent between the editor and front end:

How it's handled in trunk right now? Do we have the same issue or it's visible here with your changes?

I'm trying to grasp the problem and the naming of REST params and Query params make it a little hard..

I think that, for the scope of this PR, this should be considered the expected behavior, otherwise we have to potentially make changes to the REST API endpoint.

What changes do you think we should make in the REST API? Definitely out of scope here.

@ntsekouras
Copy link
Contributor

The "Inherit parent term from archive" control is displayed only on hierarchical taxonomy archive templates, and when active should display only children of the current queried term. This is only apparent on the front end in this PR.

Can you explain this a bit more or share a small recording?

Was it there on trunk as well?

What I tried was have the blocks with Inherit parent term from archive true in category template and tried the frontend of a top level and a nested categories. In both cases it didn't render anything..

checked={ value }
onChange={ ( inherit ) =>
onChange( {
inherit,
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 a little confused by this. Was inherit in trunk or added here? I cannot see it block.json either.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is part of making the extra termsToShow attribute redundant because it can all be handled by termQuery properties, and is an inbetween to supporting inheritance fully. This preserves the subterms functionality of termsToShow.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added inherit=false to the default termQuery object in block.json.

value={ orderBy + '/' + order }
onChange={ ( value ) => {
const [ newOrderBy, newOrder ] = value.split( '/' );
onChange( newOrderBy, newOrder );
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: we could pass the object ready for update.

// We set parent only when inheriting from the taxonomy archive context or not
// showing nested terms, otherwise nested terms are not displayed.
if (
isset( $query['inherit'] )
Copy link
Contributor

Choose a reason for hiding this comment

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

This might be related to my inherit comments. There shouldn't be a value here right now..

Copy link
Contributor

@ntsekouras ntsekouras left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I've left some comments but overall this looks good!

I haven't checked in depth the php changes in term-template, but with all the manual testing I did, it seemed to work well.

@cr0ybot
Copy link
Contributor Author

cr0ybot commented Oct 7, 2025

@ntsekouras :

How it's handled in trunk right now? Do we have the same issue or it's visible here with your changes?

Yes, the output is identical when these trunk settings are used:

Screenshot 2025-10-07 at 12 01 42 PM

And as a side note, setting max terms to "0" in trunk with the rest of the settings the same results in this discrepancy between the editor and front end:

Editor Front end
Screenshot 2025-10-07 at 12 03 07 PM Screenshot 2025-10-07 at 12 03 36 PM

I'm trying to grasp the problem and the naming of REST params and Query params make it a little hard..

Definitely feeling that too 😅. I have been working under the wrong assumption about the hierarchical argument up until now.

What changes do you think we should make in the REST API? Definitely out of scope here.

We could add a hierarchical argument to the terms controller, though I assume it might be named slightly differently because there's already been so much confusion. However I don't really think we need to tackle this any time soon.

@cr0ybot
Copy link
Contributor Author

cr0ybot commented Oct 7, 2025

@ntsekouras :

Can you explain this a bit more or share a small recording?

Was it there on trunk as well?

Yes, this is the functionality that termsToShow provided when editing a taxonomy archive template.

What I tried was have the blocks with Inherit parent term from archive true in category template and tried the frontend of a top level and a nested categories. In both cases it didn't render anything..

Do those categories have associated posts or did you set "Show empty terms" to true? My test of this functionality works as expected:

Editor Front end
Screenshot 2025-10-07 at 12 20 23 PM Screenshot 2025-10-07 at 12 21 20 PM

This is one area where a discrepancy between editor and front end is expected unless we do some additional work to query for a term to set as parent in the editor, and that could have its own flaws if the term we get has no children (making editing the term template difficult).

In my other PR I am detecting the current term if the template is for a specific term archive and fetching it as parent so that the terms are correct for both editor and front end.

Copy link
Contributor

@ntsekouras ntsekouras left a comment

Choose a reason for hiding this comment

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

Let's get this in and iterate. Thanks!

@ntsekouras ntsekouras merged commit f62bcc7 into WordPress:trunk Oct 8, 2025
70 checks passed
@github-actions github-actions bot added this to the Gutenberg 21.9 milestone Oct 8, 2025
@mikachan mikachan mentioned this pull request Oct 9, 2025
sidharthpandita1 pushed a commit to sidharthpandita1/gutenberg that referenced this pull request Oct 10, 2025
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