检索术语对象id的分类关系。
原型
get_object_term_cache( int $id, string $taxonomy )
描述
上游函数(如get_the_terms()和is_object_in_term())负责填充对象 – 术语关系缓存。当前函数仅获取缓存中已有的关系数据。
参数
$id
(int)
(Required)
术语对象ID。
$taxonomy
(string)
(Required)
分类名称。
返回值
(bool|array|WP_Error)
数组
源文件
路径:wp-includes/taxonomy.php
<?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;
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/get_object_term_cache/