clean_term_cache

函数
clean_term_cache ( $ids, $taxonomy = '', $clean_taxonomy = true )
参数
  • (int|int[]) $ids Single or array of term IDs.
    Required:
  • (string) $taxonomy Optional. Taxonomy slug. Can be empty, in which case the taxonomies of the passed term IDs will be used. Default empty.
    Required:
    Default: (empty)
  • (bool) $clean_taxonomy Optional. Whether to clean taxonomy wide caches (true), or just individual term object caches (false). Default true.
    Required:
    Default: true
定义位置
相关方法
clean_user_cacheclean_category_cacheclean_object_term_cachewp_clean_themes_cacheclean_post_cache
引入
2.3.0
弃用
-

clean_term_cache: 这个函数清除了术语的缓存。术语是分类法中的单个项目: 当这个函数被调用时,它清除了所有术语数据的缓存。

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

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_multiple( $ids, 'terms' );
		$taxonomies = array_unique( $taxonomies );
	} else {
		wp_cache_delete_multiple( $ids, 'terms' );
		$taxonomies = array( $taxonomy );
	}

	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' );
}

常见问题

FAQs
查看更多 >