Opened 2 years ago

Last modified 5 months ago

#15626 new enhancement

get_terms bug: pad_counts doesn't work if you specify parent

Reported by: yeswework Owned by:
Priority: normal Milestone: Future Release
Component: Taxonomy Version: 2.8
Severity: normal Keywords: 2nd-opinion
Cc: info@…, yeswework, mark@…, andyadamscp@…

Description

I'm not sure if this is related to #13176 or not.

Anyway, to explain the bug with an example:

Let's say you want to retrieve, via get_terms, a list of the top level categories only (by setting parent=0), but that you want the counts to include any posts assigned to subcategories too (pad_counts=1).

$categories=get_terms('category', 'pad_counts=1&parent=0');

This doesn't work: as soon as you specify parent=, it stops including the subcategory count within the parent categories. A bug, surely?

I've traced the cause to line 842 of taxonomy.php, where it checks
if ( !== $argsparent?)
and if so, sets pad_counts back to 0.

Why is that check needed at all?

Change History (7)

comment:1 in reply to: ↑ description   yeswework2 years ago

correction: line 841 of taxonomy.php

  • Keywords 2nd-opinion added
  • Milestone changed from Awaiting Review to Future Release
  • Version changed from 3.1 to 2.8

Is this a regression? The "Version" is the version you are using, but line 841 is no longer this in 3.1.

Moving the version back to 2.8 at the earliest, as that was the last commit in that area: [11476].

  • Version changed from 2.8 to 3.0.1

sorry, I set that wrongly. it's in 3.0.1

  • Type changed from defect (bug) to enhancement
  • Version changed from 3.0.1 to 2.8

To clarify -- "Version" is actually the earliest known version, so we know when a bug was introduced or how far down it affects. Generally, that will be your own version, but I quickly traced it back much farther. :-)

This also appears to be by design, so I'm setting it as an enhancement and 2nd-opinion.

  • Cc yeswework added

okay, great. thanks for your help. I found a simple enough workaround for now, but I'm interested to see whether someone can explain why it would have been by design.

  • Cc mark@… added

Even if this is not a bug (which I would dispute!), the related #17365 is.

  • Cc andyadamscp@… added

I'm curious why one wouldn't be allowed to query for parent terms with a padded count? It seems straightforward, but whoever wrote the conditional args check obviously had something in mind. Without a comment, we may never know!

Note: See TracTickets for help on using tickets.