Make WordPress Core


Ignore:
Timestamp:
02/06/2014 05:44:50 PM (13 years ago)
Author:
wonderboymusic
Message:

In get_terms(), don't set automatically hierarchical to false when parent => 0 is passed. The default value for parent is ''.

In _get_term_children(), don't skip a top-level term without first including its children in the returned term list. Ironically, the call to _get_term_children() in get_terms() has a comment stating "Make sure we show empty categories that have children.", but it didn't work if you were retrieving top-level categories only.

All unit tests pass. Added a unit test based on the use case described in this ticket.

Fixes #26903.

File:
1 edited

Legend:

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

    r27102 r27108  
    12801280        $args['offset'] = absint( $args['offset'] );
    12811281        if ( !$single_taxonomy || ! is_taxonomy_hierarchical( reset( $taxonomies ) ) ||
    1282                 '' !== $args['parent'] ) {
     1282                ( '' !== $args['parent'] && 0 !== $args['parent'] ) ) {
    12831283                $args['child_of'] = 0;
    12841284                $args['hierarchical'] = false;
    … …  
    30033003                }
    30043004
    3005                 if ( $term->term_id == $term_id )
     3005                if ( $term->term_id == $term_id ) {
     3006                        if ( isset( $has_children[$term_id] ) ) {
     3007                                foreach ( $has_children[$term_id] as $t_id ) {
     3008                                        if ( $use_id ) {
     3009                                                $term_list[] = $t_id;
     3010                                        } else {
     3011                                                $term_list[] = get_term( $t_id, $taxonomy );
     3012                                        }
     3013                                }
     3014                        }
    30063015                        continue;
     3016                }
    30073017
    30083018                if ( $term->parent == $term_id ) {
    … …  
    35253535 * Determine if a post's cache for the passed taxonomy
    35263536 *  is in sync.
    3527  * 
     3537 *
    35283538 * @since 3.9.0
    35293539 *
Note: See TracChangeset for help on using the changeset viewer.