Skip to content

Commit cc9e6ec

Browse files
committed
Call wp_update_term_count() only for those terms that have been added to or removed from the object. Props jeremyclarke. fixes #18631
git-svn-id: https://develop.svn.wordpress.org/trunk@18999 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 789dab3 commit cc9e6ec

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

wp-includes/taxonomy.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2117,6 +2117,7 @@ function wp_set_object_terms($object_id, $terms, $taxonomy, $append = false) {
21172117

21182118
$tt_ids = array();
21192119
$term_ids = array();
2120+
$new_tt_ids = array();
21202121

21212122
foreach ( (array) $terms as $term) {
21222123
if ( !strlen(trim($term)) )
@@ -2139,9 +2140,11 @@ function wp_set_object_terms($object_id, $terms, $taxonomy, $append = false) {
21392140
do_action( 'add_term_relationship', $object_id, $tt_id );
21402141
$wpdb->insert( $wpdb->term_relationships, array( 'object_id' => $object_id, 'term_taxonomy_id' => $tt_id ) );
21412142
do_action( 'added_term_relationship', $object_id, $tt_id );
2143+
$new_tt_ids[] = $tt_id;
21422144
}
21432145

2144-
wp_update_term_count($tt_ids, $taxonomy);
2146+
if ( $new_tt_ids )
2147+
wp_update_term_count( $new_tt_ids, $taxonomy );
21452148

21462149
if ( ! $append ) {
21472150
$delete_terms = array_diff($old_tt_ids, $tt_ids);

0 commit comments

Comments
 (0)