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.


Built from https://develop.svn.wordpress.org/trunk@27108


git-svn-id: http://core.svn.wordpress.org/trunk@26975 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2014-02-06 17:45:12 +00:00
parent 9419dc2fe0
commit c2b712e3b9

View File

@ -1279,7 +1279,7 @@ function get_terms($taxonomies, $args = '') {
$args['number'] = absint( $args['number'] );
$args['offset'] = absint( $args['offset'] );
if ( !$single_taxonomy || ! is_taxonomy_hierarchical( reset( $taxonomies ) ) ||
'' !== $args['parent'] ) {
( '' !== $args['parent'] && 0 !== $args['parent'] ) ) {
$args['child_of'] = 0;
$args['hierarchical'] = false;
$args['pad_counts'] = false;
@ -3002,8 +3002,18 @@ function _get_term_children($term_id, $terms, $taxonomy) {
$use_id = true;
}
if ( $term->term_id == $term_id )
if ( $term->term_id == $term_id ) {
if ( isset( $has_children[$term_id] ) ) {
foreach ( $has_children[$term_id] as $t_id ) {
if ( $use_id ) {
$term_list[] = $t_id;
} else {
$term_list[] = get_term( $t_id, $taxonomy );
}
}
}
continue;
}
if ( $term->parent == $term_id ) {
if ( $use_id )
@ -3524,7 +3534,7 @@ function set_taxonomy_last_changed( $taxonomy ) {
/**
* Determine if a post's cache for the passed taxonomy
* is in sync.
*
*
* @since 3.9.0
*
* @param int $id