#26903 closed defect (bug) (fixed)
get_terms returns no terms with 'parent' => 0 with non-empty child terms
| Reported by: | mrwweb | Owned by: | wonderboymusic |
|---|---|---|---|
| Priority: | normal | Milestone: | 3.9 |
| Component: | Taxonomy | Version: | 3.8 |
| Severity: | normal | Keywords: | has-patch commit |
| Cc: | Focuses: |
Description
I'm filing this to reopen #17365 which I think was closed incorrectly due to not understanding the OP.
I don't want to repeat the entire ticket which has a lot of good details, so read it first.
I'll illustrate the bug with an example...
Consider the following Food taxonomy term hierarchy and counts:
- Cheese (0)
- Cheddar (2)
- Brie (7)
- Crackers (0)
- Butter (1)
- Multigrain (3)
- Fruit (0)
- Cranberries (0)
This structure implies 9 cheese posts, 4 cracker posts, and no fruit posts.
According to the get_terms documentation, get_terms( 'my_food_tax', array( 'parent' => 0 ) ) should return Cheese and Crackers because hierarchical defaults to true and those terms (Cheese and Crackers) have non-empty children (Cheddar, Brie, Butter, and Multigrain). However, this currently returns NO terms.
As the OP points out, this seems to be because setting 'parent' => 0 resets some of the stated defaults.
However, this isn't just a problem with accurate documentation. As best I can tell, there is no way to override this behavior so the expected return value (Cheese and Crackers) is impossible to achieve without some kind of hack. I tried adding 'pad_counts' => true and 'hierarchical' => true in hopes that would help but it doesn't.
Attachments (1)
Change History (12)
#3
@
12 years ago
- Resolution → fixed
- Status new → closed
Fixed in [27108], which for some reason didn't post here or trigger an email.
#4
@
12 years ago
- Resolution fixed
- Status closed → reopened
Last night, it came to me that I didn't write tests for parent => 0 and more than one-level deep of empties before hitting a term with count > 0
#8
follow-up:
↓ 9
@
12 years ago
- Resolution fixed
- Status closed → reopened
The unit test is randomly failing for me.
Tests_Term_getTerms::test_get_terms_seven_levels_deep Failed asserting that an array is not empty. tests/phpunit/tests/term/getTerms.php:323
#9
in reply to: ↑ 8
;
follow-up:
↓ 10
@
12 years ago
- Resolution → fixed
- Status reopened → closed
Replying to markjaquith:
The unit test is randomly failing for me.
See comment:ticket:14485:88, it's handled there.
#10
in reply to: ↑ 9
@
12 years ago
Replying to SergeyBiryukov:
Replying to markjaquith:
The unit test is randomly failing for me.
See comment:ticket:14485:88, it's handled there.
That's a really awkward workaround to counteract something that shouldn't be happening. [27115] should just be reverted.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
This was another brutal one.
_get_term_children()was defying logic in some cases. All unit tests pass. I added a mega unit test that does exactly what this ticket describes. Gonna let this sit til tomorrow in case someone wants to chime in.