Make WordPress Core

Changeset 12729


Ignore:
Timestamp:
01/15/2010 05:40:37 PM (15 years ago)
Author:
ryan
Message:

Support id=>parent in fields arg of get_terms. Returns array of parent ids keyed by the id of the child term.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/taxonomy.php

    r12711 r12729  
    798798    if ( 'all' == $fields )
    799799        $selects = array('t.*', 'tt.*');
    800     else if ( 'ids' == $fields )
     800    else if ( 'ids' == $fields || 'id=>parent' == $fields )
    801801        $selects = array('t.term_id', 'tt.parent', 'tt.count');
    802802    else if ( 'names' == $fields )
    803803        $selects = array('t.term_id', 'tt.parent', 'tt.count', 't.name');
    804         $select_this = implode(', ', apply_filters( 'get_terms_fields', $selects, $args ));
     804    $select_this = implode(', ', apply_filters( 'get_terms_fields', $selects, $args ));
    805805
    806806    $query = "SELECT $select_this FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy IN ($in_taxonomies) $where ORDER BY $orderby $order $limit";
     
    845845
    846846    $_terms = array();
    847     if ( 'ids' == $fields ) {
     847    if ( 'id=>parent' == $fields ) {
     848        while ( $term = array_shift($terms) )
     849            $_terms[$term->term_id] = $term->parent;
     850        $terms = $_terms;
     851    } elseif ( 'ids' == $fields ) {
    848852        while ( $term = array_shift($terms) )
    849853            $_terms[] = $term->term_id;
     
    20672071
    20682072    $children = array();
    2069     $terms = get_terms($taxonomy, array('get' => 'all', 'orderby' => 'id', 'fields' => 'ids'));
    2070     foreach ( $terms as $term ) {
    2071         if ( $term->parent > 0 )
    2072             $children[$term->parent][] = $term->term_id;
     2073    $terms = get_terms($taxonomy, array('get' => 'all', 'orderby' => 'id', 'fields' => 'id=>parent'));
     2074    foreach ( $terms as $term_id => $parent ) {
     2075        if ( $parent > 0 )
     2076            $children[$parent][] = $term_id;
    20732077    }
    20742078    set_transient("{$taxonomy}_children", $children);
Note: See TracChangeset for help on using the changeset viewer.