clean_object_term_cache

Removes the taxonomy relationship to terms from the cache.

Description

clean_object_term_cache( (int|array) $object_ids, (array|string) $object_type ); 

Will remove the entire taxonomy relationship containing term $object_id.. The term IDs have to exist within the taxonomy $object_type for the deletion to take place.

Parameters (2)

0. $object_ids (int|array)
Single or list of term object ID(s).
1. $object_type (array|string)
The taxonomy object type.

Usage

  1. if ( !function_exists( 'clean_object_term_cache' ) ) { 
  2. require_once ABSPATH . WPINC . '/taxonomy.php'; 
  3.  
  4. // Single or list of term object ID(s). 
  5. $object_ids = null; 
  6.  
  7. // The taxonomy object type. 
  8. $object_type = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = clean_object_term_cache($object_ids, $object_type); 
  12.  

Defined (1)

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

/wp-includes/taxonomy.php  
  1. function clean_object_term_cache($object_ids, $object_type) { 
  2. global $_wp_suspend_cache_invalidation; 
  3.  
  4. if ( ! empty( $_wp_suspend_cache_invalidation ) ) { 
  5. return; 
  6.  
  7. if ( !is_array($object_ids) ) 
  8. $object_ids = array($object_ids); 
  9.  
  10. $taxonomies = get_object_taxonomies( $object_type ); 
  11.  
  12. foreach ( $object_ids as $id ) { 
  13. foreach ( $taxonomies as $taxonomy ) { 
  14. wp_cache_delete($id, "{$taxonomy}_relationships"); 
  15.  
  16. /** 
  17. * Fires after the object term cache has been cleaned. 
  18. * @since 2.5.0 
  19. * @param array $object_ids An array of object IDs. 
  20. * @param string $objet_type Object type. 
  21. */ 
  22. do_action( 'clean_object_term_cache', $object_ids, $object_type );