Opened 3 years ago
Last modified 2 years ago
#56264 new feature request
WP_Term_Query does not allow limiting results when descending family tree
Reported by: | get_dave | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 2.7.1 |
Component: | Taxonomy | Keywords: | |
Focuses: | Cc: |
Description
The Problem
Over in https://github.com/WordPress/gutenberg/pull/42424 we're working on a way to limit the number of Category taxonomy terms that are displayed in the UI.
This works well until you attempt to display top level terms only (i.e. those with a parent of 0). In this case the limit is not applied.
Here is the Gutenberg PHP code where we apply the parent argument:
Why does this happen?
Digging into the Core code I noticed that WP_Term_Query->get_terms()
method explicitly does not allow limiting when descending into the family tree of terms or when a parent is provided:
The code comment states:
Don't limit the query results when we have to descend the family tree.
There is no further information.
Further investigation reveals that this "feature" was present in the original commit which introduced this functionality:
Feature Request
I would like to display the top X categories but showing top level terms only. As it stands I don't believe this is possible.
Perhaps we could introduce a clause in the conditional which allows limiting if the $parent
is 0
?
Change History (3)
#2
@
3 years ago
I just noticed this line which seems to suggest this should already work
This was introduced in [10416] for #8832 and has followed various refactors since then.