is_tax() WP 2.5.0
Works on the custom taxonomy archive page. Conditional tag.
Returns true
if a new taxonomy is registered and the user has visited the page of this taxonomy element (term).
It is similar to is_category(), is_tag(), but does not replace them. It works only with new custom taxonomies. I.e. is_tax()
returns false
on the category or tag archive page!
Returns false
if the query_var
parameter is not defined for the taxonomy while registering the taxonomy. See: register_taxonomy().
If the $taxonomy
parameter is specified, this function will additionally check if the query is for that specific $taxonomy
.
If the $term
parameter is specified in addition to the $taxonomy
parameter, this function will additionally check if the query is for one of the terms specified.
For more information on this and similar theme functions, check out the Conditional Tags article in the Theme Developer Handbook.
If you want to check whether the post is in a taxonomy, use has_term()
- Global. WP_Query.
$wp_query
Global WP_Query instance.
WP_Query::is_tax()
No Hooks.
Return
true/false. True for custom taxonomy archive pages, false for built-in taxonomies (category and tag archives).
Usage
if( is_tax( $taxonomy, $term ) ){ // it is taxonomy... }
- $taxonomy(string/array)
- Taxonomy slug or slugs. You can specify multiple taxonomies in an array.
Default: '' - $term(int/string/array)
- Term ID, name, slug or array of Term IDs, names, and slugs.
Default: ''
Examples
#1 Check that we are on a taxonomy archive page
Below are some examples of when the is_tax()
function returns true
(works).
is_tax(); // When any custom taxonomy archive page is being displayed. is_tax( 'channel' ); // When the archive page for taxonomy of 'channel' is being displayed. is_tax( 'channel', 'BBC1' ); // When the archive page for taxonomy of 'channel' is being displayed and the 'channel' taxonomy term is 'BBC1'. is_tax( 'channel', array( 'BBC1', 'SNN' ) ); // When the archive page for taxonomy of 'channel' is being displayed and the 'channel' taxonomy term is 'BBC1' or 'SNN'.
#2 Specificity with "Post Format" taxonomy
Post formats in WP are implemented through taxonomy. However, the slug of "Post Format" taxonomy element is not used as it is used in other taxes: the post-format- prefix is added to it.
For example, there is a post format "Aside" with the slug "aside". Its name will be post-format-aside, but not simple aside
.
if( is_tax( 'post_format' ) ){ // archive page for any "Post Format". } if( is_tax( 'post_format', 'post-format-aside' ) ){ // archive page for 'aside' "Post Format". }
Code of is tax:
wp-includes/query.php
VER 5.0.3
Related Functions
From tag: Conditional tags (page type and request)
- is_404()
- is_admin()
- is_archive()
- is_attachment()
- is_author()
- is_blog_admin()
- is_category()
- is_comment_feed()
- is_customize_preview()
- is_date()
- is_day()
- is_embed()
More from tag: Conditional tags (all)
- cat_is_ancestor_of()
- comments_open()
- email_exists()
- has_category()
- has_custom_header()
- has_excerpt()
- has_nav_menu()
- has_post_thumbnail()
- has_shortcode()
- has_tag()
- has_term()
- have_comments()
- have_posts()
- in_category()
- in_the_loop()
More from category: Queries
More from Template Tags: Main Functions
- bloginfo()
- calendar_week_mod()
- get_bloginfo()
- get_calendar()
- get_current_blog_id()
- get_footer()
- get_header()
- get_search_form()
- get_sidebar()