Opened 10 years ago
Closed 10 years ago
#39932 closed defect (bug) (fixed)
`get_terms()` with `name` and without `taxonomy` generates warning
| Reported by: | dlh | Owned by: | boonebgorges |
|---|---|---|---|
| Priority: | normal | Milestone: | 4.8 |
| Component: | Taxonomy | Version: | |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
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.
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.