I would like to display a text depends of my custom taxonomy category, like:
if custom post type category is X, then echo Text Y.
I’ve tried this, but its not working:
global $post;
if (($post->post_type == 'myposttype') && is_category('slug-name-of-cat')) {
echo 'My text'
}
any ideias?
is_category()
does not work on custom taxonomy archive pages. The correct conditional tag here isis_tax()
which takes the name of the taxonomy as first parameter and a string|int|array of term name/s, slug/s or ID/s as second parameter.So your whole conditional statement can look something like :
EDIT
In addition, to test whether a post belongs to a specific term, you should use
has_term()
to test for the specific termThe conditional
is_*
functions work on query, not on current post. In other words they tell you things about page you are on, however not about the current post.is_category()
will check if current page is category archivehas_category()
will check if post has specific category assignedFrom your description I suspect you mean the latter.
Refer to this codex for detailed understanding:
https://codex.wordpress.org/Function_Reference/get_categories
You can do something like this: