Make WordPress Core

Opened 6 years ago

Closed 5 years ago

#46768 closed defect (bug) (fixed)

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

Reported by: planvova's profile planvova Owned by: sergeybiryukov's profile SergeyBiryukov
Milestone: 5.5 Priority: normal
Severity: normal Version: 3.7
Component: Taxonomy Keywords: has-patch has-unit-tests
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 (2)

46768.diff (662 bytes) - added by Howdy_McGee 5 years ago.
Adds tt.parent to id=>name and id=>slug to account for child_of and parent
46768.2.diff (2.4 KB) - added by deepaklalwani 5 years ago.
Adds unit test cases

Download all attachments as: .zip

Change History (8)

#1 @SergeyBiryukov
6 years 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
5 years ago

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

#2 @Howdy_McGee
5 years 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.

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


5 years ago

#4 @SergeyBiryukov
5 years ago

  • Milestone changed from Future Release to 5.5
  • Owner set to SergeyBiryukov
  • Severity changed from major to normal
  • Status changed from new to reviewing

@deepaklalwani
5 years ago

Adds unit test cases

#5 @deepaklalwani
5 years ago

  • Keywords has-unit-tests added; needs-unit-tests removed

Attached a patch for unit test cases

#6 @SergeyBiryukov
5 years ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 48663:

Taxonomy: Ensure the child_of argument of get_terms() works as expected with 'fields' => 'id=>name' or 'id=>slug'.

Props Howdy_McGee, deepaklalwani, planvova.
Fixes #46768.

Note: See TracTickets for help on using tickets.