返回介绍

get_object_term_cache()

发布于 2017-09-10 23:39:13 字数 3245 浏览 919 评论 0 收藏 0

get_object_term_cache( int $id,  string $taxonomy )

Retrieves the taxonomy relationship to the term object id.


description

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.


参数

$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;
}

更新日志

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

相关函数

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

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文