Make WordPress Core

Opened 6 years ago

Last modified 5 months ago

#44279 reopened defect (bug)

`get_terms()` with `child_of` and `childless` combined

Reported by: nonverbla's profile nonverbla Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 4.9.6
Component: Taxonomy Keywords: has-unit-tests needs-patch
Focuses: Cc:

Description

Hi there! I'm not sure if I found a bug or this is intended behaviour: If I use a combination of childless and child_of in a get_terms call, I get zero results.
My taxonomy's structure:

- Genre
-- Hip Hop
-- Trap
-- Rap
- Location
-- Europe
--- Germany
--- Sweden
--- Austria
-- Asia
--- China
--- Japan
--- Taiwan

My code:

<?php
$location_parent = get_term(123, 'my_custom_taxonomy');

$countries = get_terms(array(
  'taxonomy' => $location_parent->taxonomy,
  'hide_empty' => false,
  'child_of' => $location_parent->term_id, 
  'childless' => true
));

I'm trying to only list countries, basically children of 'location' that don't have children of their own.

Attachments (1)

44279.test.diff (1.3 KB) - added by boonebgorges 6 years ago.

Download all attachments as: .zip

Change History (7)

#1 @boonebgorges
6 years ago

  • Keywords reporter-feedback added

Hi @nonverbla - Thanks for the ticket. I'm unable to reproduce the problem with a unit test - see 44279.test.diff, which is passing. Can you have a look at that test to see if I've accurately captured what you're describing?

#2 @nonverbla
5 months ago

  • Keywords reporter-feedback removed

Sorry @boonebgorges, I absolutely missed that this ticket got a reply 6 years ago!! If there is a passing unit test already in place, I'm trusting that much more than myself.

This ticket was mentioned in Slack in #core by nonverbla. View the logs.


5 months ago

#4 @oglekler
5 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

I am closing this ticket because this issue is not replicated so far and this case is covered by Unit tests.

This ticket was mentioned in PR #6201 on WordPress/wordpress-develop by @jorbin.


5 months ago
#5

  • Keywords has-patch has-unit-tests added

#6 @jorbin
5 months ago

  • Keywords needs-patch added; has-patch removed
  • Milestone set to Future Release
  • Resolution invalid deleted
  • Status changed from closed to reopened

I think that the test doesn't actually show the case described in the ticket so I updated it.

The test originally demonstrated direct children, but not all levels of children. To use the locations example, the test would return Antarctica which has no nations.

Note: See TracTickets for help on using tickets.