has_term()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
has_term( string|int|array $term = '', string $taxonomy = '', int|WP_Post|null $post = null ): bool
Описание
Указанные термины сверяются с term_ids, именами и слагами терминов записи.
Термины, заданные целыми числами, сверяются только с term_ids терминов записи.
Если термины не указаны, определяет, есть ли у записи какие-либо термины.
Оригинал (английский)
The given terms are checked against the post’s terms’ term_ids, names and slugs.
Terms given as integers will only be checked against the post’s terms’ term_ids.
If no terms are given, determines if post has any terms.
Параметры
$term
string|int|array
необязательный
= ''
$taxonomy
string
необязательный
= ''
$post
int|WP_Post|null
необязательный
= null
Возвращаемое значение
bool
Исходный код
wp-includes/category-template.php:1542
function has_term( $term = '', $taxonomy = '', $post = null ) {
$post = get_post( $post );
if ( ! $post ) {
return false;
}
$r = is_object_in_term( $post->ID, $taxonomy, $term );
if ( is_wp_error( $r ) ) {
return false;
}
return $r;
}
История изменений
| Версия | Описание |
|---|---|
| 3.1.0 | Introduced. |

