将从缓存中删除所有术语ID。

原型

clean_term_cache( int|array $ids, string $taxonomy = '', bool $clean_taxonomy = true )

参数

$ids (int|array) (Required) 单个或列表的术语ID。

$taxonomy (string) (Optional)  可以为空并假设为tt_ids,否则将用于上下文。

$clean_taxonomy (bool) (Optional)  是否清除分类广泛的缓存(true),或仅仅是单个术语对象缓存(false)。

源文件

路径:wp-includes/taxonomy.php

<?php
...
function clean_term_cache($ids, $taxonomy = '', $clean_taxonomy = true) {
	global $wpdb, $_wp_suspend_cache_invalidation;
	if ( ! empty( $_wp_suspend_cache_invalidation ) ) {
		return;
	}
	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, 'terms' );
		}
		$taxonomies = array_unique($taxonomies);
	} else {
		$taxonomies = array($taxonomy);
		foreach ( $taxonomies as $taxonomy ) {
			foreach ( $ids as $id ) {
				wp_cache_delete( $id, 'terms' );
			}
		}
	}
	foreach ( $taxonomies as $taxonomy ) {
		if ( $clean_taxonomy ) {
			clean_taxonomy_cache( $taxonomy );
		}
		/**
		 * Fires once after each taxonomy's term cache has been cleaned.
		 *
		 * @since 2.5.0
		 * @since 4.5.0 Added the `$clean_taxonomy` parameter.
		 *
		 * @param array  $ids            An array of term IDs.
		 * @param string $taxonomy       Taxonomy slug.
		 * @param bool   $clean_taxonomy Whether or not to clean taxonomy-wide caches
		 */
		do_action( 'clean_term_cache', $ids, $taxonomy, $clean_taxonomy );
	}
	wp_cache_set( 'last_changed', microtime(), 'terms' );
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/clean_term_cache/