WordPress.org

Make WordPress Core

Opened 12 months ago

Last modified 3 weeks ago

#46768 new defect (bug)

Not working get_terms with parameters 'child_of' and 'fields'=>'id=>name'

Reported by: planvova Owned by:
Milestone: Future Release Priority: normal
Severity: major Version: 3.7
Component: Taxonomy Keywords: needs-unit-tests has-patch
Focuses: Cc:

Description

When I tried select all child terms from my category I had an error
PHP Notice: Undefined property: stdClass::$parent in /wp-includes/taxonomy.php on line 3529

I used
$terms = get_terms(
['taxonomy' => 'my_taxonomy_name',
'child_of' => TERM_ID,
'fields' => 'id=>name']
);

And I have empty result and notice on logs.
If I remove parameter "fields", it works fine.
Or if change 'fields' to 'ids' or 'names'.

Attachments (1)

46768.diff (662 bytes) - added by Howdy_McGee 3 weeks ago.
Adds tt.parent to id=>name and id=>slug to account for child_of and parent

Download all attachments as: .zip

Change History (3)

#1 @SergeyBiryukov
11 months ago

  • Keywords needs-unit-tests added
  • Milestone changed from Awaiting Review to Future Release
  • Version changed from trunk to 3.7

Hi @planvova, welcome to WordPress Trac! Thanks for the report.

Introduced in [25161].

@Howdy_McGee
3 weeks ago

Adds tt.parent to id=>name and id=>slug to account for child_of and parent

#2 @Howdy_McGee
3 weeks ago

  • Keywords has-patch added; needs-patch removed

The names fields param already accounts for grabbing the tt.parent. I don't see why we can't do the same for both id=>name and id=>slug. I've added a patch that simply adds these in which should address the issue.

Note: See TracTickets for help on using tickets.