WordPress.org

Make WordPress Core

Opened 17 months ago

Closed 13 days ago

#46768 closed defect (bug) (fixed)

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

Reported by: planvova Owned by: 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 months 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 6 weeks ago.
Adds unit test cases

Download all attachments as: .zip

Change History (8)

#1 @SergeyBiryukov
16 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
5 months ago

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

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


4 months ago

#4 @SergeyBiryukov
4 months 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
6 weeks ago

Adds unit test cases

#5 @deepaklalwani
6 weeks ago

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

Attached a patch for unit test cases

#6 @SergeyBiryukov
13 days 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.