Make WordPress Core

Opened 15 years ago

Closed 11 years ago

#13661 closed enhancement (fixed)

Support id=>name in fields arg of get_terms()

Reported by: mikeschinkel's profile mikeschinkel Owned by: wonderboymusic's profile wonderboymusic
Milestone: 3.7 Priority: normal
Severity: normal Version: 3.0
Component: Taxonomy Keywords: has-patch commit
Focuses: Cc:

Description

In trying to use get_terms() I found it didn't support what seemed a common use case; an array where keys were $term->term_id and the values where $term->name.

This patch adds functionailty for a "id=>name" in fields arg of get_terms(). It returns array of term names keyed by the term id.

This path is similar to changeset:12729 by ryan on 2010-Jan-15.

I searched for a similar ticket but didn't find anything recently related.

Attachments (4)

adds-fields=id=>name-to-get_terms().diff (793 bytes) - added by mikeschinkel 15 years ago.
Add support for "id=>name" in "fields" arg of get_terms() function. Returns array of term names keyed by term id.
adds-new-options-to-fields-for-get_terms().diff (1014 bytes) - added by mikeschinkel 15 years ago.
Adds a choice of "id=>name" and "id=>slug" for the "fields" argument passed as the 3rd parameter of get_terms() in /wp-includes/taxonomy.php. This choice makes the returned array from get_terms() contains array keys equal to $term->term_id and arrays values equal to $term->name, and array keys equal to $term->slug and arrays values equal to $term->name, respectively.
13661.diff (2.2 KB) - added by wonderboymusic 11 years ago.
13661.2.diff (3.8 KB) - added by wonderboymusic 11 years ago.

Download all attachments as: .zip

Change History (11)

@mikeschinkel
15 years ago

Add support for "id=>name" in "fields" arg of get_terms() function. Returns array of term names keyed by term id.

@mikeschinkel
15 years ago

Adds a choice of "id=>name" and "id=>slug" for the "fields" argument passed as the 3rd parameter of get_terms() in /wp-includes/taxonomy.php. This choice makes the returned array from get_terms() contains array keys equal to $term->term_id and arrays values equal to $term->name, and array keys equal to $term->slug and arrays values equal to $term->name, respectively.

#1 @mikeschinkel
15 years ago

Ugh. Just as soon as I posted this I realize I really also needed slug=>name. New patch attached.

#2 @kevinB
14 years ago

  • Cc kevinB added

#3 @nacin
14 years ago

  • Milestone changed from Awaiting Review to Future Release

#4 @wonderboymusic
11 years ago

  • Keywords needs-testing added
  • Milestone changed from Future Release to 3.7

Refreshed this patch, was blowing up against trunk

#5 @wonderboymusic
11 years ago

#14448 was marked as a duplicate.

#6 @wonderboymusic
11 years ago

  • Keywords commit added; needs-testing removed

.2.diff has unit tests

#7 @wonderboymusic
11 years ago

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

In 25161:

Support id=>name and id=>slug values for fields arg in get_terms(). Adds unit tests.

Props mikeschinkel.

Fixes #13661.

Note: See TracTickets for help on using tickets.