_update_generic_term_count

Will update term count based on number of objects.

Description

_update_generic_term_count( (array) $terms, (object) $taxonomy ); 

Default callback for the link_category taxonomy.

Parameters (2)

0. $terms (array)
List of term taxonomy IDs.
1. $taxonomy (object)
Current taxonomy object of terms.

Usage

  1. if ( !function_exists( '_update_generic_term_count' ) ) { 
  2. require_once ABSPATH . WPINC . '/taxonomy.php'; 
  3.  
  4. // List of term taxonomy IDs. 
  5. $terms = array(); 
  6.  
  7. // Current taxonomy object of terms. 
  8. $taxonomy = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = _update_generic_term_count($terms, $taxonomy); 
  12.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/taxonomy.php  
  1. function _update_generic_term_count( $terms, $taxonomy ) { 
  2. global $wpdb; 
  3.  
  4. foreach ( (array) $terms as $term ) { 
  5. $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term ) ); 
  6.  
  7. /** This action is documented in wp-includes/taxonomy.php */ 
  8. do_action( 'edit_term_taxonomy', $term, $taxonomy->name ); 
  9. $wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) ); 
  10.  
  11. /** This action is documented in wp-includes/taxonomy.php */ 
  12. do_action( 'edited_term_taxonomy', $term, $taxonomy->name );