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

wordpress函数get_object_term_cache()用法示例

get_object_term_cache( int $id,  string $taxonomy )

Retrieves the taxonomy relationship to the term object id.


描述

Upstream functions (like get_the_terms() and is_object_in_term()) are responsible for populating the object-term relationship cache. The current function only fetches relationship data that is already in the cache.

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包


参数

$id

(int)
(Required)
Term object ID.

$taxonomy

(string)
(Required)
Taxonomy name.


返回值

(bool|array|WP_Error) Array of WP_Term objects, if cached. False if cache is empty for $taxonomy and $id. WP_Error if get_term() returns an error object for any term.


源代码

File: wp-includes/taxonomy.php

function get_object_term_cache( $id, $taxonomy ) {
	$_term_ids = wp_cache_get( $id, "{$taxonomy}_relationships" );

	// We leave the priming of relationship caches to upstream functions.
	if ( false === $_term_ids ) {
		return false;
	}

	// Backward compatibility for if a plugin is putting objects into the cache, rather than IDs.
	$term_ids = array();
	foreach ( $_term_ids as $term_id ) {
		if ( is_numeric( $term_id ) ) {
			$term_ids[] = intval( $term_id );
		} elseif ( isset( $term_id->term_id ) ) {
			$term_ids[] = intval( $term_id->term_id );
		}
	}

	// Fill the term objects.
	_prime_term_caches( $term_ids );

	$terms = array();
	foreach ( $term_ids as $term_id ) {
		$term = get_term( $term_id, $taxonomy );
		if ( is_wp_error( $term ) ) {
			return $term;
		}

		$terms[] = $term;
	}

	return $terms;
}

更新日志

Version 描述
4.7.0 Returns a WP_Error object if get_term() returns an error for any of the matched terms.
2.3.0 Introduced.

相关函数

Uses

  • wp-includes/taxonomy.php:
    _prime_term_caches()
  • wp-includes/cache.php:
    wp_cache_get()
  • wp-includes/taxonomy.php:
    get_term()
  • wp-includes/load.php:
    is_wp_error()

Used By

  • wp-includes/post.php:
    wp_queue_posts_for_term_meta_lazyload()
  • wp-admin/includes/taxonomy.php:
    get_terms_to_edit()
  • wp-admin/includes/template.php:
    get_inline_data()
  • wp-admin/includes/media.php:
    get_attachment_fields_to_edit()
  • wp-admin/includes/media.php:
    get_compat_media_markup()
  • wp-includes/category-template.php:
    get_the_terms()
  • wp-includes/taxonomy.php:
    get_the_taxonomies()
  • wp-includes/taxonomy.php:
    is_object_in_term()
  • Show 3 more used by
    Hide more used by


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

热门推荐

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

反馈