Ticket #13661: adds-fields=id=>name-to-get_terms().diff

File adds-fields=id=>name-to-get_terms().diff, 793 bytes (added by mikeschinkel, 3 years ago)

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

Line 
1Index: trunk/wp-includes/taxonomy.php
2===================================================================
3--- trunk/wp-includes/taxonomy.php      (revision 15065)
4+++ trunk/wp-includes/taxonomy.php      (revision )
5@@ -984,6 +984,9 @@
6                        $orderby = '';
7                        $order = '';
8                        $selects = array('COUNT(*)');
9+               case 'id=>name':
10+                       $selects = array('t.term_id', 't.name');
11+                       break;
12        }
13     $select_this = implode(', ', apply_filters( 'get_terms_fields', $selects, $args ));
14 
15@@ -1045,6 +1048,10 @@
16                while ( $term = array_shift($terms) )
17                        $_terms[] = $term->name;
18                $terms = $_terms;
19+       } elseif ( 'id=>name' == $fields ) {
20+               while ( $term = array_shift($terms) )
21+                       $_terms[$term->term_id] = $term->name;
22+               $terms = $_terms;
23        }
24 
25        if ( 0 < $number && intval(@count($terms)) > $number ) {