WordPress.org

Make WordPress Core

Ticket #18631: 18658.diff

File 18658.diff, 843 bytes (added by jeremyclarke, 7 years ago)

Fix wp_set_object_terms to only reset count on affected terms

  • wp-includes/taxonomy.php

     
    21152115
    21162116        $tt_ids = array();
    21172117        $term_ids = array();
     2118        $new_tt_ids = array();
    21182119
    21192120        foreach ( (array) $terms as $term) {
    21202121                if ( !strlen(trim($term)) )
     
    21372138                do_action( 'add_term_relationship', $object_id, $tt_id );
    21382139                $wpdb->insert( $wpdb->term_relationships, array( 'object_id' => $object_id, 'term_taxonomy_id' => $tt_id ) );
    21392140                do_action( 'added_term_relationship', $object_id, $tt_id );
     2141                $new_tt_ids[] = $tt_id;
    21402142        }
     2143        if (count($new_tt_ids))
     2144                wp_update_term_count($new_tt_ids, $taxonomy);
    21412145
    2142         wp_update_term_count($tt_ids, $taxonomy);
    21432146
    21442147        if ( ! $append ) {
    21452148                $delete_terms = array_diff($old_tt_ids, $tt_ids);