| 1347 | | if ( $children = _get_term_children($term->term_id, $terms, $taxonomy) ) { |
|---|
| 1348 | | foreach ( $children as $child ) { |
|---|
| 1349 | | $child = get_term($child, $taxonomy); |
|---|
| 1350 | | $terms[$key]->count += $child->count; |
|---|
| 1351 | | } |
|---|
| 1352 | | } |
|---|
| 1353 | | } |
|---|
| | 1355 | $terms_by_id[$term->term_id] = & $terms[$key]; |
|---|
| | 1356 | $term_ids[$term->term_taxonomy_id] = $term->term_id; |
|---|
| | 1357 | } |
|---|
| | 1358 | |
|---|
| | 1359 | // Get the object and term ids and stick them in a lookup table |
|---|
| | 1360 | $results = $wpdb->get_results("SELECT object_id, term_taxonomy_id FROM $wpdb->term_relationships LEFT JOIN $wpdb->posts ON object_id = ID WHERE term_taxonomy_id IN (".join(',', array_keys($term_ids)).") AND post_type = 'post' AND post_status = 'publish'"); |
|---|
| | 1361 | foreach ( $results as $row ) { |
|---|
| | 1362 | $id = $term_ids[$row->term_taxonomy_id]; |
|---|
| | 1363 | ++$term_items[$id][$row->object_id]; |
|---|
| | 1364 | } |
|---|
| | 1365 | |
|---|
| | 1366 | // Touch every ancestor's lookup row for each post in each term |
|---|
| | 1367 | foreach ( $term_ids as $term_id ) { |
|---|
| | 1368 | $child = $term_id; |
|---|
| | 1369 | while ( $parent = $terms_by_id[$child]->parent ) { |
|---|
| | 1370 | if ( !empty($term_items[$term_id]) ) |
|---|
| | 1371 | foreach ( $term_items[$term_id] as $item_id => $touches ) |
|---|
| | 1372 | ++$term_items[$parent][$item_id]; |
|---|
| | 1373 | $child = $parent; |
|---|
| | 1374 | } |
|---|
| | 1375 | } |
|---|
| | 1376 | |
|---|
| | 1377 | // Transfer the touched cells |
|---|
| | 1378 | foreach ( (array) $term_items as $id => $items ) |
|---|
| | 1379 | if ( isset($terms_by_id[$id]) ) |
|---|
| | 1380 | $terms_by_id[$id]->count = count($items); |
|---|