Skip to content

Conversation

@kmanijak
Copy link
Contributor

@kmanijak kmanijak commented Aug 26, 2025

What?

Part of #49094.

This PR adds "Max terms" setting in Terms Query block. It limits the number of terms being displayed. The setting is only available if "Show hierarchical" data is disabled since there's not "right" way of limiting terms then.

Note

Mind this PR is targeting #70720 not trunk

Why?

This is to allow creating more appealing layouts (e.g. showing hundreds of categories may be overwhelming and simply ugly) and highlighting some categories.

How?

Testing Instructions

  1. Ensure experimental blocks are enabled.
  2. Insert the Terms Query block in a template.
  3. Expected: Max Terms is 10 by default and up to 10 terms are displayed
  4. Change it to 0
  5. Expected: All terms are displayed. Verify on the frontend it's the same!
  6. Change to some numbers
  7. Expected: Correct number of terms is displayed. Verify on the frontend it's the same!
  8. Enable "Show hierarchy"
  9. Expected: Max Terms setting is hidden and all terms are displayed again

Testing Instructions for Keyboard

Screenshots or screencast

image

@kmanijak kmanijak changed the title Terms Query: add Max Terms control [WIP] Terms Query: add Max Terms control Aug 26, 2025
@kmanijak kmanijak marked this pull request as ready for review August 27, 2025 14:26
@github-actions
Copy link

github-actions bot commented Aug 27, 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>

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

'per_page' => $query['perPage'] ?? 100,
'page' => $query['pages'] ?? 1,
'taxonomy' => $query['taxonomy'] ?? 'category',
'number' => $query['perPage'] ?? 10,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As per https://developer.wordpress.org/reference/classes/wp_term_query/ there's no page argument and we should use number instead of per_page.

Copy link
Member

Choose a reason for hiding this comment

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

Nice, good spot!

@mikachan mikachan self-requested a review August 27, 2025 14:38
@kmanijak kmanijak mentioned this pull request Aug 27, 2025
15 tasks
@kmanijak kmanijak changed the title [WIP] Terms Query: add Max Terms control Terms Query: add Max Terms control Aug 28, 2025
@mikachan mikachan added the [Type] Enhancement A suggestion for improvement. label Aug 28, 2025
Copy link
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.

Thanks for working on this, it's testing really well for me 🙌

I've just left one small wording suggestion, but othewise I think this is good to bring in when the conflicts are resolved.

'per_page' => $query['perPage'] ?? 100,
'page' => $query['pages'] ?? 1,
'taxonomy' => $query['taxonomy'] ?? 'category',
'number' => $query['perPage'] ?? 10,
Copy link
Member

Choose a reason for hiding this comment

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

Nice, good spot!

@kmanijak
Copy link
Contributor Author

kmanijak commented Aug 29, 2025

Thanks @mikachan , I addressed your comment and resolved conflicts! 🙌

@kmanijak kmanijak requested a review from mikachan August 29, 2025 07:52
@kmanijak kmanijak mentioned this pull request Aug 29, 2025
Copy link
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.

LGTM!

@mikachan
Copy link
Member

mikachan commented Sep 1, 2025

I'm not sure why this Storybook test isn't running. I've tried re-running it a couple of times. Maybe we should try merging the main branch in again?

@kmanijak
Copy link
Contributor Author

kmanijak commented Sep 1, 2025

I'm not sure why this Storybook test isn't running. I've tried re-running it a couple of times. Maybe we should try merging the main branch in again?

Updating the branch didn't help 😅 I see it passes on other contributions and I've no idea why it's failing here. Also, I can't re-run myself 😓

@mikachan
Copy link
Member

mikachan commented Sep 1, 2025

No problem, I'll try to figure it out. Maybe the main branch needs rebasing with trunk, but then the Storybook check has passed there. It's not even a failed check, it looks like the environment is struggling to install the Storybook deps.

We could even merge the PR regardless, as it's not going directly to trunk anyway. Maybe I'll end up doing that 😅

@mikachan mikachan force-pushed the add/terms-query-block-container branch from de054eb to 9cbbd4e Compare September 1, 2025 12:17
@mikachan mikachan force-pushed the add/terms-query-block-container branch from 9cbbd4e to de054eb Compare September 1, 2025 14:22
@mikachan
Copy link
Member

mikachan commented Sep 1, 2025

I think the base branch needed updating with trunk 🤔 Anyway, looks like we're good to go now!

@mikachan mikachan merged commit 28048ca into WordPress:add/terms-query-block-container Sep 1, 2025
67 checks passed
@t-hamano t-hamano added the [Block] Terms Query Affects the Terms Query Block label Sep 11, 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