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.
Built from https://develop.svn.wordpress.org/trunk@31248


git-svn-id: http://core.svn.wordpress.org/trunk@31229 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Boone Gorges 2015-01-19 16:52:22 +00:00
parent 067ee8c476
commit 61f5f38dcd
2 changed files with 7 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 // Touch every ancestor's lookup row for each post in each term
$ancestors = array();
foreach ( $term_ids as $term_id ) { foreach ( $term_ids as $term_id ) {
$ancestors[] = $term_id;
$child = $term_id; $child = $term_id;
$ancestors = array();
while ( !empty( $terms_by_id[$child] ) && $parent = $terms_by_id[$child]->parent ) { while ( !empty( $terms_by_id[$child] ) && $parent = $terms_by_id[$child]->parent ) {
if ( in_array( $parent, $ancestors ) ) { $ancestors[] = $child;
break;
}
if ( !empty( $term_items[$term_id] ) ) if ( !empty( $term_items[$term_id] ) )
foreach ( $term_items[$term_id] as $item_id => $touches ) { 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; $term_items[$parent][$item_id] = isset($term_items[$parent][$item_id]) ? ++$term_items[$parent][$item_id]: 1;
} }
$child = $parent; $child = $parent;
if ( in_array( $parent, $ancestors ) ) {
break;
}
} }
} }

View File

@ -4,7 +4,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '4.2-alpha-31247'; $wp_version = '4.2-alpha-31248';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.