Make WordPress Core


Ignore:
Timestamp:
10/30/2014 02:11:56 AM (11 years ago)
Author:
boonebgorges
Message:

In get_terms(), do not override 'hierarchical' and 'pad_counts' when 'parent' is present.

The previous behavior resulted in descendant terms being improperly excluded
from the results when passing a 'parent', even when 'hierarchical' had been
set to true.

The patch also adds unit tests that demonstrate the various interactions
between the 'child_of', 'parent', and 'hierarchical' parameters of get_terms().

Props landakram.
Fixes #29815.

File:
1 edited

Legend:

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

    r30105 r30107  
    16291629    $args['number'] = absint( $args['number'] );
    16301630    $args['offset'] = absint( $args['offset'] );
    1631     if ( !$single_taxonomy || ! is_taxonomy_hierarchical( reset( $taxonomies ) ) ||
    1632         ( '' !== $args['parent'] && 0 !== $args['parent'] ) ) {
    1633         $args['child_of'] = 0;
     1631
     1632    // Save queries by not crawling the tree in the case of multiple taxes or a flat tax.
     1633    if ( ! $single_taxonomy || ! is_taxonomy_hierarchical( reset( $taxonomies ) ) ) {
     1634        $args['child_of'] = false;
    16341635        $args['hierarchical'] = false;
    16351636        $args['pad_counts'] = false;
     1637    }
     1638
     1639    // 'parent' overrides 'child_of'.
     1640    if ( 0 < intval( $args['parent'] ) ) {
     1641        $args['child_of'] = false;
    16361642    }
    16371643
Note: See TracChangeset for help on using the changeset viewer.