Changeset 5558
- Timestamp:
- 05/27/2007 06:17:50 AM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/taxonomy.php
r5557 r5558 2 2 3 3 $wp_taxonomies = 4 array('category' => array('object_type' => 'post', 'hierarchical' => true ),5 'post_tag' => array('object_type' => 'post', 'hierarchical' => false ),4 array('category' => array('object_type' => 'post', 'hierarchical' => true, 'update_count_callback' => '_update_post_term_count'), 5 'post_tag' => array('object_type' => 'post', 'hierarchical' => false, 'update_count_callback' => '_update_post_term_count'), 6 6 'link_category' => array('object_type' => 'link', 'hierarchical' => false)); 7 7 … … 112 112 $taxonomies = array($taxonomies); 113 113 114 $terms = get_object_terms($object_id, $taxonomies, 'fields=tt_ids');115 $in_terms = "'" . implode("', '", $terms) . "'";116 $wpdb->query("DELETE FROM $wpdb->term_relationships WHERE object_id = '$object_id' AND term_taxonomy_id IN ($in_terms)");117 118 // Assume all taxonomies have the same object type 119 $taxonomy = get_taxonomy($taxonomies[0]);120 wp_update_term_count($terms, $taxonomy['object_type']);114 foreach ( $taxonomies as $taxonomy ) { 115 $terms = get_object_terms($object_id, $taxonomy, 'fields=tt_ids'); 116 $in_terms = "'" . implode("', '", $terms) . "'"; 117 $wpdb->query("DELETE FROM $wpdb->term_relationships WHERE object_id = '$object_id' AND term_taxonomy_id IN ($in_terms)"); 118 119 wp_update_term_count($terms, $taxonomy); 120 } 121 121 122 122 // TODO clear the cache … … 238 238 } 239 239 240 function wp_update_term_count( $terms, $ object_type) {240 function wp_update_term_count( $terms, $taxonomy ) { 241 241 if ( empty($terms) ) 242 242 return false; 243 243 244 // TODO validate object_type245 246 244 if ( !is_array($terms) ) 247 245 $terms = array($terms); … … 249 247 $terms = array_map('intval', $terms); 250 248 251 do_action("count_${object_type}_terms", $terms); 249 $taxonomy = get_taxonomy($taxonomy); 250 if ( isset($taxonomy['update_count_callback']) ) 251 return call_user_func($taxonomy['update_count_callback'], $terms); 252 253 // Default count updater 254 $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = '$term'"); 255 $wpdb->query("UPDATE $wpdb->term_taxonomy SET count = '$count' WHERE term_taxonomy_id = '$term'"); 252 256 253 257 return true; … … 310 314 $terms = array($terms); 311 315 312 if ( ! $append ) { 313 $old_terms = $wpdb->get_col("SELECT tr.term_taxonomy_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy = '$taxonomy' AND tr.object_id = '$object_id'"); 314 if ( empty($old_terms) ) 315 $old_terms = array(); 316 } 316 if ( ! $append ) 317 $old_terms = get_object_terms($object_id, $taxonomy, 'fields=tt_ids'); 317 318 318 319 $tt_ids = array(); … … 330 331 } 331 332 332 $taxonomy_data = get_taxonomy($taxonomy); 333 wp_update_term_count($tt_ids, $taxonomy_data['object_type']); 333 wp_update_term_count($tt_ids, $taxonomy); 334 334 335 335 if ( ! $append ) { … … 339 339 $wpdb->query("DELETE FROM $wpdb->term_relationships WHERE term_taxonomy_id IN ($delete_terms)"); 340 340 $wpdb->query("UPDATE $wpdb->term_taxonomy SET count = count - 1 WHERE term_taxonomy_id IN ($delete_terms)"); 341 wp_update_term_count($delete_terms, $taxonomy_data['object_type']); 342 } 343 } 344 341 wp_update_term_count($delete_terms, $taxonomy); 342 } 343 } 344 345 // TODO clean old_terms. Need term_id instead of tt_id 345 346 clean_term_cache($term_ids, $taxonomy); 346 347 … … 683 684 } 684 685 } 685 add_action('count_post_terms', '_update_post_term_count');686 687 function _update_link_term_count( $terms ) {688 global $wpdb;689 690 foreach ( $terms as $term ) {691 $count = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = '$term'");692 $wpdb->query("UPDATE $wpdb->term_taxonomy SET count = '$count' WHERE term_taxonomy_id = '$term'");693 }694 }695 add_action('count_link_terms', '_update_link_term_count');696 686 697 687 ?>
Note: See TracChangeset
for help on using the changeset viewer.