WP_Query::is_tag() public WP 3.1.0
Is the query for an existing tag archive page?
If the $tag parameter is specified, this function will additionally check if the query is for one of the tags specified.
{} Это метод класса: WP_Query{}
Хуков нет.
Возвращает
true/false. Whether the query is for an existing tag archive page.
Использование
global $wp_query; $wp_query->is_tag( $tag );
- $tag(число/строка/число[]/строка[])
- Tag ID, name, slug, or array of such to check against.
По умолчанию: ''
Список изменений
С версии 3.1.0 | Введена. |
Код WP_Query::is_tag() WP Query::is tag WP 5.6.2
public function is_tag( $tag = '' ) {
if ( ! $this->is_tag ) {
return false;
}
if ( empty( $tag ) ) {
return true;
}
$tag_obj = $this->get_queried_object();
$tag = array_map( 'strval', (array) $tag );
if ( in_array( (string) $tag_obj->term_id, $tag, true ) ) {
return true;
} elseif ( in_array( $tag_obj->name, $tag, true ) ) {
return true;
} elseif ( in_array( $tag_obj->slug, $tag, true ) ) {
return true;
}
return false;
}