wp_update_term_count_now

Perform term count update immediately.

Description

wp_update_term_count_now( (array) $terms, (string) $taxonomy ); 

Parameters (2)

0. $terms (array)
The term_taxonomy_id of terms to update.
1. $taxonomy (string)
The context of the term.

Usage

  1. if ( !function_exists( 'wp_update_term_count_now' ) ) { 
  2. require_once ABSPATH . WPINC . '/taxonomy.php'; 
  3.  
  4. // The term_taxonomy_id of terms to update. 
  5. $terms = array(); 
  6.  
  7. // The context of the term. 
  8. $taxonomy = ''; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = wp_update_term_count_now($terms, $taxonomy); 
  12.  

Defined (1)

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

/wp-includes/taxonomy.php  
  1. function wp_update_term_count_now( $terms, $taxonomy ) { 
  2. $terms = array_map('intval', $terms); 
  3.  
  4. $taxonomy = get_taxonomy($taxonomy); 
  5. if ( !empty($taxonomy->update_count_callback) ) { 
  6. call_user_func($taxonomy->update_count_callback, $terms, $taxonomy); 
  7. } else { 
  8. $object_types = (array) $taxonomy->object_type; 
  9. foreach ( $object_types as &$object_type ) { 
  10. if ( 0 === strpos( $object_type, 'attachment:' ) ) 
  11. list( $object_type ) = explode( ':', $object_type ); 
  12.  
  13. if ( $object_types == array_filter( $object_types, 'post_type_exists' ) ) { 
  14. // Only post types are attached to this taxonomy 
  15. _update_post_term_count( $terms, $taxonomy ); 
  16. } else { 
  17. // Default count updater 
  18. _update_generic_term_count( $terms, $taxonomy ); 
  19.  
  20. clean_term_cache($terms, '', false); 
  21.  
  22. return true;