wp_update_term_count

Updates the amount of terms in taxonomy.

Description

wp_update_term_count( (int|array) $terms, (string) $taxonomy, (bool) $do_deferred = false ); 

If there is a taxonomy callback applied, then it will be called for updating the count.

The default action is to count what the amount of terms have the relationship of term ID. Once that is done, then update the database.

Parameters (3)

0. $terms (int|array)
The term_taxonomy_id of the terms.
1. $taxonomy (string)
The context of the term.
2. $do_deferred — Optional. (bool) => false
Whether to flush the deferred term counts too. Default false.

Usage

  1. if ( !function_exists( 'wp_update_term_count' ) ) { 
  2. require_once ABSPATH . WPINC . '/taxonomy.php'; 
  3.  
  4. // The term_taxonomy_id of the terms. 
  5. $terms = null; 
  6.  
  7. // The context of the term. 
  8. $taxonomy = ''; 
  9.  
  10. // Whether to flush the deferred term counts too. Default false. 
  11. $do_deferred = false; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = wp_update_term_count($terms, $taxonomy, $do_deferred); 
  15.  

Defined (1)

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

/wp-includes/taxonomy.php  
  1. function wp_update_term_count( $terms, $taxonomy, $do_deferred = false ) { 
  2. static $_deferred = array(); 
  3.  
  4. if ( $do_deferred ) { 
  5. foreach ( (array) array_keys($_deferred) as $tax ) { 
  6. wp_update_term_count_now( $_deferred[$tax], $tax ); 
  7. unset( $_deferred[$tax] ); 
  8.  
  9. if ( empty($terms) ) 
  10. return false; 
  11.  
  12. if ( !is_array($terms) ) 
  13. $terms = array($terms); 
  14.  
  15. if ( !isset($_deferred[$taxonomy]) ) 
  16. $_deferred[$taxonomy] = array(); 
  17. $_deferred[$taxonomy] = array_unique( array_merge($_deferred[$taxonomy], $terms) ); 
  18. return true; 
  19.  
  20. return wp_update_term_count_now( $terms, $taxonomy );