get_the_terms
apply_filters( ‘get_the_terms’, WP_Term[]|WP_Error $terms , int $post_id , string $taxonomy )
过滤器::过滤附加到给定文章的术语列表。Filter Hook: Filters the list of terms attached to the given post.
参数(Parameters)
参数 | 类型 | 说明 |
---|---|---|
$terms | (WP_Term[] | WP_Error) | 附加条款的数组,或失败时的WP_错误。 |
$post_id | (int) | 邮政编码。 |
$taxonomy | (string) | 分类法的名称。 |
源码(Source)
/** * Retrieve the terms of the taxonomy that are attached to the post. * * @since 2.5.0 * * @param int|object $post Post ID or object. * @param string $taxonomy Taxonomy name. * @return array|false|WP_Error Array of term objects on success, false if there are no terms * or the post does not exist, WP_Error on failure. */function get_the_terms( $post, $taxonomy ) {if ( ! $post = get_post( $post ) )return false;$terms = get_object_term_cache( $post->ID, $taxonomy );if ( false === $terms ) {$terms = wp_get_object_terms( $post->ID, $taxonomy );wp_cache_add($post->ID, $terms, $taxonomy . ‘_relationships’);}/** * Filter the list of terms attached to the given post. * * @since 3.1.0 * * @param array|WP_Error $terms List of attached terms, or WP_Error on failure. * @param int $post_id Post ID. * @param string $taxonomy Name of the taxonomy. */$terms = apply_filters( ‘get_the_terms’, $terms, $post->ID, $taxonomy );if ( empty( $terms ) )return false;return $terms;}
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
3.1.0 | wp-includes/category-template.php:1260 | 1 | 0 |
总计 0 评论