Make WordPress Core

Ticket #29839: 29839.diff

File 29839.diff, 2.4 KB (added by horike, 11 years ago)
  • wp-includes/taxonomy.php

     
    16401640
    16411641        $defaults = array('orderby' => 'name', 'order' => 'ASC',
    16421642                'hide_empty' => true, 'exclude' => array(), 'exclude_tree' => array(), 'include' => array(),
    1643                 'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '',
     1643                'number' => '', 'fields' => 'all', 'slug' => '', 'parent' => '', 'child' => '',
    16441644                'hierarchical' => true, 'child_of' => 0, 'get' => '', 'name__like' => '', 'description__like' => '',
    16451645                'pad_counts' => false, 'offset' => '', 'search' => '', 'cache_domain' => 'core' );
    16461646        $args = wp_parse_args( $args, $defaults );
     
    16541654                $args['pad_counts'] = false;
    16551655        }
    16561656
    1657         // 'parent' overrides 'child_of'.
    1658         if ( 0 < intval( $args['parent'] ) ) {
     1657        // 'parent' and 'child' overrides 'child_of'.
     1658        if ( 0 < intval( $args['parent'] ) || 0 < intval( $args['child'] ) ) {
    16591659                $args['child_of'] = false;
    16601660        }
    16611661
     
    16921692                }
    16931693        }
    16941694
     1695        $child = $args['child'];
     1696        if ( $child ) {
     1697                $hierarchy = _get_term_hierarchy( reset( $taxonomies ) );
     1698                if ( ! isset( $hierarchy[ $child ] ) ) {
     1699                        return $empty_array;
     1700                }
     1701        }
     1702
    16951703        // $args can be whatever, only use the args defined in defaults to compute the key
    16961704        $filter_key = ( has_filter('list_terms_exclusions') ) ? serialize($GLOBALS['wp_filter']['list_terms_exclusions']) : '';
    16971705        $key = md5( serialize( wp_array_slice_assoc( $args, array_keys( $defaults ) ) ) . serialize( $taxonomies ) . $filter_key );
     
    18531861        $offset = $args['offset'];
    18541862
    18551863        // don't limit the query results when we have to descend the family tree
    1856         if ( $number && ! $hierarchical && ! $child_of && '' === $parent ) {
     1864        if ( $number && ! $hierarchical && ! $child_of && '' === $parent && '' === $child ) {
    18571865                if ( $offset ) {
    18581866                        $limits = 'LIMIT ' . $offset . ',' . $number;
    18591867                } else {
     
    19511959                }
    19521960        }
    19531961
     1962        if ( $child ) {
     1963                $children = _get_term_hierarchy( reset( $taxonomies ) );
     1964                if ( ! empty( $children ) ) {
     1965                        $terms = _get_term_children( $child, $terms, reset( $taxonomies ) );
     1966                        foreach ( $terms as $k => $term ) {
     1967                                if ( isset( $children[$term->term_id] ) )
     1968                                        unset($terms[$k]);
     1969                        }
     1970                }
     1971        }
     1972
    19541973        // Update term counts to include children.
    19551974        if ( $args['pad_counts'] && 'all' == $_fields ) {
    19561975                _pad_term_counts( $terms, reset( $taxonomies ) );