检索附加到帖子的分类法的条款。

原型

get_the_terms( int|object $post, string $taxonomy )

参数

$post (int|object) (Required) 邮政ID或对象。

$taxonomy (string) (Required) 分类名称。

返回值

(array|false|WP_Error)  数组

源文件

路径:wp-includes/category-template.php

<?php
...
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 );
		if ( ! is_wp_error( $terms ) ) {
			$term_ids = wp_list_pluck( $terms, 'term_id' );
			wp_cache_add( $post->ID, $term_ids, $taxonomy . '_relationships' );
		}
	}
	/**
	 * Filters 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;
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/get_the_terms/