^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 5年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云1核2g仅需102元/年,今日10点开抢

wordpress函数clean_term_cache()用法示例

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

Will remove all of the term ids from the cache.


描述


参数

$ids

(int|array)
(Required)
Single or list of Term IDs.

$taxonomy

(string)
(Optional)
Can be empty and will assume tt_ids, else will use for context.

Default value: ”

$clean_taxonomy

(bool)
(Optional)
Whether to clean taxonomy wide caches (true), or just individual term object caches (false).

Default value: true


源代码

File: wp-includes/taxonomy.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 ) {
			wp_cache_delete('all_ids', $taxonomy);
			wp_cache_delete('get', $taxonomy);
			delete_option("{$taxonomy}_children");
			// Regenerate {$taxonomy}_children
			_get_term_hierarchy($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' );
}

更新日志

Version 描述
2.3.0 Introduced.

相关函数

Uses

  • wp-includes/cache.php:
    wp_cache_delete()
  • wp-includes/cache.php:
    wp_cache_set()
  • wp-includes/taxonomy.php:
    clean_term_cache
  • wp-includes/plugin.php:
    do_action()
  • wp-includes/option.php:
    delete_option()
  • wp-includes/wp-db.php:
    wpdb::get_results()
  • Show 1 more use
    Hide more uses


Used By

  • wp-includes/category.php:
    clean_category_cache()
  • wp-includes/taxonomy.php:
    wp_update_term_count_now()
  • wp-includes/taxonomy.php:
    wp_update_term()
  • wp-includes/taxonomy.php:
    wp_insert_term()
  • wp-includes/taxonomy.php:
    wp_delete_term()
  • wp-includes/ms-functions.php:
    global_terms()
  • Show 1 more used by
    Hide more used by


User Contributed Notes

让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈