Changeset 6159
- Timestamp:
- 09/23/2007 12:35:59 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/taxonomy.php
r6157 r6159 1339 1339 // Assumes all relevant children are already in the $terms argument 1340 1340 function _pad_term_counts(&$terms, $taxonomy) { 1341 global $wpdb; 1342 1343 // This function only works for post categories. 1344 if ( 'category' != $taxonomy ) 1345 return; 1346 1341 1347 $term_hier = _get_term_hierarchy($taxonomy); 1342 1348 … … 1344 1350 return; 1345 1351 1352 $term_items = array(); 1353 1346 1354 foreach ( $terms as $key => $term ) { 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); 1354 1381 } 1355 1382
Note: See TracChangeset
for help on using the changeset viewer.