Better loop detection for _pad_term_counts().

The `$ancestors` check must be reset for each term in order for term counts
to be correct.

Fixes #20635.

git-svn-id: https://develop.svn.wordpress.org/trunk@31248 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Boone Gorges
2015-01-19 16:51:44 +00:00
parent 2c955c0bbf
commit d80ca82693
2 changed files with 49 additions and 7 deletions

View File

@@ -3920,20 +3920,20 @@ function _pad_term_counts(&$terms, $taxonomy) {
}
// Touch every ancestor's lookup row for each post in each term
$ancestors = array();
foreach ( $term_ids as $term_id ) {
$ancestors[] = $term_id;
$child = $term_id;
$ancestors = array();
while ( !empty( $terms_by_id[$child] ) && $parent = $terms_by_id[$child]->parent ) {
if ( in_array( $parent, $ancestors ) ) {
break;
}
$ancestors[] = $child;
if ( !empty( $term_items[$term_id] ) )
foreach ( $term_items[$term_id] as $item_id => $touches ) {
$term_items[$parent][$item_id] = isset($term_items[$parent][$item_id]) ? ++$term_items[$parent][$item_id]: 1;
}
$child = $parent;
if ( in_array( $parent, $ancestors ) ) {
break;
}
}
}