WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#39932 closed defect (bug) (fixed)

`get_terms()` with `name` and without `taxonomy` generates warning

Reported by: dlh Owned by: boonebgorges
Milestone: 4.8 Priority: normal
Severity: normal Version:
Component: Taxonomy Keywords:
Focuses: Cc:

Description

On a clean install, calling get_terms( array( 'name' => array( 'uncategorized' ) ) ) generates a warning: reset() expects parameter 1 to be array, null given in...class-wp-term-query.php on line 481.

Earlier in WP_Term_Query::get_terms(), the $taxonomies variable is set to $args['taxonomy'], but that argument is null by default.

The attached patch would cast $args['taxonomy'] to an array before assigning it to $taxonomies. Casting to an array fixes the warning and seems consistent to me with the use of $taxonomies throughout the method, which tends to assume it's an array.

Attachments (1)

39932.diff (509 bytes) - added by dlh 4 years ago.

Download all attachments as: .zip

Change History (3)

@dlh
4 years ago

#1 @boonebgorges
4 years ago

  • Milestone changed from Awaiting Review to 4.8

Yes, I think this is right. Previously, it wasn't possible to query for terms without passing a taxonomy, so this problem never really arose in the past.

#2 @boonebgorges
4 years ago

  • Owner set to boonebgorges
  • Resolution set to fixed
  • Status changed from new to closed

In 40147:

Taxonomy: When querying terms, ensure $taxonomies is an array.

This avoids PHP notices that otherwise arise when no taxonomy
parameter is passed to get_terms() or WP_Term_Query.

Props dlh.
Fixes #39932.

Note: See TracTickets for help on using tickets.