функция
since 2.5.0
get_the_terms()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
get_the_terms( int|WP_Post $post, string $taxonomy ): WP_Term[]|false|WP_Error
Описание
Получает термины таксономии, прикреплённые к записи.
Параметры
$post
int|WP_Post
обязательный
Идентификатор или объект записи.
$taxonomy
string
обязательный
Имя таксономии.
Возвращаемое значение
WP_Term[]|false|WP_Error
WP_Term WP_Error
Исходный код
wp-includes/category-template.php:1288
function get_the_terms( $post, $taxonomy ) {
$post = get_post( $post );
if ( ! $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 WP_Term[]|WP_Error $terms Array 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;
}
История изменений
| Версия | Описание |
|---|---|
| 2.5.0 | Introduced. |

