Is there any experience using widget logic, I want to display a widget on single custom post type with specific taxonomy. Tried using
is_tax(taxonomy_name) || is_single() && in_term(term_name).
Before I start, I must say that your terminology is quite confusing and plain wrong. You should take your time and read through my answer to this question: Is There a Difference Between Taxonomies and Categories?
As I stated before, there is no in_term()
function to check if a post has a specific term. There is however a has_term()
function which accepts the term as first parameter and the taxonomy name as second parameter. So your condition should look like this: (if this is for a specific post type outside the loop)
global $post;
if ( $post->post_type == 'my_post_type' // checks the post type of the post
&& is_single() // Checks if this is a single post
&& has_term( 'term-name or id or slug', 'my_taxonomy', $post->ID ) // Check if post has specific term
) {
// Do something if our condition is true
}
Please try below code:
if(has_tag( array( 'sharp', 'mild', 'extreme' ) ) && get_post_type()=="custom-post-type"){
}
The array value should be the term name which is stored in taxonomy.
You can directly pass the array in has_tag()
function
has_tag()
will not work. It works for the build in taxonomy post_tag
, not a custom taxonomy
Commented
Jun 22, 2015 at 12:23
gas_tag()
function. I have corrected that
Commented
Jun 22, 2015 at 12:25
in_term()
according to my knowledge is invalid