WP_Query::is_tag
Determines whether the query is 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(int|строка|int[]|string[])
- Tag ID, name, slug, or array of such to check against.
По умолчанию:''
Список изменений
| С версии 3.1.0 | Введена. |
Код WP_Query::is_tag() WP Query::is tag WP 7.0
public function is_tag( $tag = '' ) {
if ( ! $this->is_tag ) {
return false;
}
if ( empty( $tag ) ) {
return true;
}
$tag_obj = $this->get_queried_object();
if ( ! $tag_obj ) {
return false;
}
$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;
}