Make WordPress Core

Opened 12 years ago

Closed 9 years ago

#15626 closed enhancement (wontfix)

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

Reported by: yeswework's profile yeswework Owned by:
Milestone: Priority: normal
Severity: normal Version: 2.8
Component: Taxonomy Keywords:
Focuses: Cc:


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 (8)

#1 in reply to: ↑ description @yeswework
12 years ago

correction: line 841 of taxonomy.php

#2 @nacin
12 years ago

  • 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].

#3 @yeswework
12 years ago

  • Version changed from 2.8 to 3.0.1

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

#4 @nacin
12 years ago

  • 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.

#5 @yeswework
12 years ago

  • 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.

#6 @mark8barnes
12 years ago

  • Cc mark@… added

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

#7 @andyadams
10 years ago

  • 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!

#8 @wonderboymusic
9 years ago

  • Keywords 2nd-opinion removed
  • Milestone Future Release deleted
  • Resolution set to wontfix
  • Status changed from new to closed

#17365 was closed as worksforme - this ticket is 3 years old, wontfix'ing

Note: See TracTickets for help on using tickets.