I have created Custom Post Type called - listing

Also created custom taxonomy - listingcategories

In listing categories, i have created two categories

  1. music 2. features

Now i want to create a conditional statement for music category

I am trying this, but its not working

<?php global $post;
if (($post->post_type == 'listing') && is_category('music')) { 
} ?>

Am i using it right is_category() ?

Please Help.

Thanks Rajiv

  • It seems it should work, but can you also update the code you have used to register the custom post type and the custom taxonomy. Commented Oct 25, 2013 at 8:25
  • i used custom post type creator. By which it created default categories
    – luckyrajiv
    Commented Oct 25, 2013 at 8:28
  • and where are you using the above set of codes? Commented Oct 25, 2013 at 8:36
  • in single-listing.php
    – luckyrajiv
    Commented Oct 25, 2013 at 9:07
  • can you update your code with whole code from that file Commented Oct 25, 2013 at 9:57

3 Answers 3


Cheers guy's this helped me a lot, I used the below which works great, any improvements appreciated.

          $cat1 = array('category1', 'category2');

           if( has_term( $cat1, 'my_custom_post_type' ) ) {
                  //do something
         } else { //do somthing else}?>
         <?php if( has_term( 'music', 'listingcategory' ) ) {

Got working using this http://codex.wordpress.org/Function_Reference/has_term


The is_category() conditional applies to a specific taxonomy: category. The category taxonomy, by default, is only registered for the post post-type.

You're using a custom post type - listing - and a custom taxonomy - listingcategories. As such, you will not be able to use is_category() to construct conditional statements for them.

You can use one of the following, depending on your needs:

  • is_tax( $taxonomy, $term ): returns true if the current page is a taxonomy archive index:

    is_tax( 'listingcategories', 'music' )
  • has_term( $taxonomy, $term ): returns true if the current post has the specified taxonomy term applied:

    has_term( 'listingcategories', 'music' )

So, the analog to your original code would be:

<?php global $post;
if ( ($post->post_type == 'listing') && is_tax( 'listingcategories', 'music' ) ) { 
} ?>

And cleaned up using get_post_type():

if ( 'listingcategories' == get_post_type() && is_tax( 'listingcategories', 'music' ) ) {
    // statement

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.