get_object_term_cache
函数
get_object_term_cache ( $id, $taxonomy )
- 参数
-
-
(int)
$id
Term object ID, for example a post, comment, or user ID.- Required: 是
-
(string)
$taxonomy
Taxonomy name.- Required: 是
-
(int)
- 返回值
-
- (bool|WP_Term[]|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.
- 定义位置
-
-
wp-includes/taxonomy.php
, line 3670
-
wp-includes/taxonomy.php
- 引入
- 2.3.0
- 弃用
- –
Retrieves the cached term objects for the given 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.
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[] = (int) $term_id; } elseif ( isset( $term_id->term_id ) ) { $term_ids[] = (int) $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; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。