Opened 3 months ago

Last modified 3 months ago

#23506 new defect (bug)

get_terms() assumes its taxonomies argument is a numeric array with a 0 key

Reported by: nbachiyski Owned by:
Priority: normal Milestone: Awaiting Review
Component: Taxonomy Version: trunk
Severity: normal Keywords: has-patch
Cc:

Description

In a few places in get_terms() we are using $taxonomies[0] after we've established that we have more than one taxonomy. The array isn't always 0-based, though.

For example, get_taxonomies() returns arrays with the taxonomy name as a key, which breaks this pattern.

In the attached patch, the taxonomies are run through array_values(), which gives us a 0-based array of the taxonomies.

Attachments (1)

get-terms-0-based-taxonomies.diff (543 bytes) - added by nbachiyski 3 months ago.

Download all attachments as: .zip

Change History (5)

  • Summary changed from get_terms() assumes its taxonomies argument is 0-based to get_terms() assumes its taxonomies argument is a numeric array

Fixing ticket title to clearer terminology. Probably worth updating the patch too.

comment:3 follow-up: ↓ 4   nbachiyski3 months ago

I still think 0-based is the better term.

The array, which is a result of $a = array( 1, 2, 3); unset( $a[0] ); is still numeric, but its zeroth element is missing.

comment:4 in reply to: ↑ 3   Viper007Bond3 months ago

  • Summary changed from get_terms() assumes its taxonomies argument is a numeric array to get_terms() assumes its taxonomies argument is a numeric array with a 0 key

Replying to nbachiyski:

I still think 0-based is the better term.

The array, which is a result of $a = array( 1, 2, 3); unset( $a[0] ); is still numeric, but its zeroth element is missing.

True!

Note: See TracTickets for help on using tickets.