WordPress.org

Make WordPress Core

Ticket #13661: adds-new-options-to-fields-for-get_terms().diff

File adds-new-options-to-fields-for-get_terms().diff, 1014 bytes (added by mikeschinkel, 5 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.

  • trunk/wp-includes/taxonomy.php

     
    984984                        $orderby = ''; 
    985985                        $order = ''; 
    986986                        $selects = array('COUNT(*)'); 
     987                case 'id=>name': 
     988                        $selects = array('t.term_id', 't.name'); 
     989                        break; 
     990                case 'id=>slug': 
     991                        $selects = array('t.slug', 't.name'); 
     992                        break; 
    987993        } 
    988994    $select_this = implode(', ', apply_filters( 'get_terms_fields', $selects, $args )); 
    989995 
     
    10451051                while ( $term = array_shift($terms) ) 
    10461052                        $_terms[] = $term->name; 
    10471053                $terms = $_terms; 
     1054        } elseif ( 'id=>name' == $fields ) { 
     1055                while ( $term = array_shift($terms) ) 
     1056                        $_terms[$term->term_id] = $term->name; 
     1057                $terms = $_terms; 
     1058        } elseif ( 'id=>slug' == $fields ) { 
     1059                while ( $term = array_shift($terms) ) 
     1060                        $_terms[$term->term_id] = $term->slug; 
     1061                $terms = $_terms; 
    10481062        } 
    10491063 
    10501064        if ( 0 < $number && intval(@count($terms)) > $number ) {