WordPress.org

Make WordPress Core

Opened 16 months ago

Last modified 14 months ago

#44279 new defect (bug)

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

Reported by: nonverbla Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version: 4.9.6
Component: Taxonomy Keywords: reporter-feedback
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 14 months ago.

Download all attachments as: .zip

Change History (2)

#1 @boonebgorges
14 months 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?

Note: See TracTickets for help on using tickets.