Definition:
function clean_term_cache($ids, $taxonomy = '', $clean_taxonomy = true) {}
Will remove all of the term ids from the cache.
Parameters
- int|array $ids: Single or list of Term IDs
- string $taxonomy: Can be empty and will assume tt_ids, else will use for context.
- bool $clean_taxonomy: Whether to clean taxonomy wide caches (true), or just individual term object caches (false). Default is true.
Defined actions
- clean_term_cache
do_action('clean_term_cache', $ids, $taxonomy);
Source code
function clean_term_cache($ids, $taxonomy = '', $clean_taxonomy = true) { global $wpdb; static $cleaned = array(); if ( !is_array($ids) ) $ids = array($ids); $taxonomies = array(); // If no taxonomy, assume tt_ids. if ( empty($taxonomy) ) { $tt_ids = array_map('intval', $ids); $tt_ids = implode(', ', $tt_ids); $terms = $wpdb->get_results("SELECT term_id, taxonomy FROM $wpdb->term_taxonomy WHERE term_taxonomy_id IN ($tt_ids)"); $ids = array(); foreach ( (array) $terms as $term ) { $taxonomies[] = $term->taxonomy; $ids[] = $term->term_id; wp_cache_delete($term->term_id, $term->taxonomy); } $taxonomies = array_unique($taxonomies); } else { $taxonomies = array($taxonomy); foreach ( $taxonomies as $taxonomy ) { foreach ( $ids as $id ) { wp_cache_delete($id, $taxonomy); } } } foreach ( $taxonomies as $taxonomy ) { if ( isset($cleaned[$taxonomy]) ) continue; $cleaned[$taxonomy] = true; if ( $clean_taxonomy ) { wp_cache_delete('all_ids', $taxonomy); wp_cache_delete('get', $taxonomy); delete_option("{$taxonomy}_children"); // Regenerate {$taxonomy}_children _get_term_hierarchy($taxonomy); } do_action('clean_term_cache', $ids, $taxonomy); }
631
No comments yet... Be the first to leave a reply!