Make WordPress Core


Ignore:
Timestamp:
01/26/2015 07:03:09 PM (10 years ago)
Author:
boonebgorges
Message:

Ensure that 'hierarchical' is respected in get_terms() when multiple taxonomies are passed.

Previously, attempts to descend the family tree of each term were done using
the first taxonomy in the $taxonomies array, with the result that terms not
belonging to that taxonomy were not found and their children not properly
parsed. We fix this bug by fetching each term's taxonomy with the SQL query,
and then using that taxonomy to get the correct children for each term.

Fixes #31118.

File:
1 edited

Legend:

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

    r31284 r31285  
    18881888        case 'ids':
    18891889        case 'id=>parent':
    1890             $selects = array( 't.term_id', 'tt.parent', 'tt.count' );
     1890            $selects = array( 't.term_id', 'tt.parent', 'tt.count', 'tt.taxonomy' );
    18911891            break;
    18921892        case 'names':
    1893             $selects = array( 't.term_id', 'tt.parent', 'tt.count', 't.name' );
     1893            $selects = array( 't.term_id', 'tt.parent', 'tt.count', 't.name', 'tt.taxonomy' );
    18941894            break;
    18951895        case 'count':
     
    18991899            break;
    19001900        case 'id=>name':
    1901             $selects = array( 't.term_id', 't.name', 'tt.count' );
     1901            $selects = array( 't.term_id', 't.name', 'tt.count', 'tt.taxonomy' );
    19021902            break;
    19031903        case 'id=>slug':
    1904             $selects = array( 't.term_id', 't.slug', 'tt.count' );
     1904            $selects = array( 't.term_id', 't.slug', 'tt.count', 'tt.taxonomy' );
    19051905            break;
    19061906    }
     
    19751975        }
    19761976    }
     1977
    19771978    // Make sure we show empty categories that have children.
    19781979    if ( $hierarchical && $args['hide_empty'] && is_array( $terms ) ) {
    19791980        foreach ( $terms as $k => $term ) {
    19801981            if ( ! $term->count ) {
    1981                 $children = get_term_children( $term->term_id, reset( $taxonomies ) );
     1982                $children = get_term_children( $term->term_id, $term->taxonomy );
    19821983                if ( is_array( $children ) ) {
    19831984                    foreach ( $children as $child_id ) {
    1984                         $child = get_term( $child_id, reset( $taxonomies ) );
     1985                        $child = get_term( $child_id, $term->taxonomy );
    19851986                        if ( $child->count ) {
    19861987                            continue 2;
Note: See TracChangeset for help on using the changeset viewer.