how can I use the in_category for custom post types? here is my code.

<?php get_header('shop'); ?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); global $_product; $_product = new jigoshop_product( $post->ID ); ?>

    <?php do_action('jigoshop_before_single_product', $post, $_product); ?>

    <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
         <div id="productssidebar">

        <?php if (function_exists('dynamic_sidebar') && dynamic_sidebar('Lesson Sidebar')) : else : ?>
        <?php endif; ?>
        <?php do_action('jigoshop_before_single_product_summary', $post, $_product); ?>

        <div class="summary">
            <h1 id="pack">Lesson Pack</h1>
            <h1 class="product_title page-title"><?php the_title(); ?></h1>

            <?php do_action( 'jigoshop_template_single_summary', $post, $_product ); ?>


        <div id ="pack-desc" style="margin-top: 293px;">
        <?php the_content();?>
        <?php do_action('jigoshop_after_single_product_summary', $post, $_product ); ?>
        <!--END IF-->


    <?php do_action('jigoshop_after_single_product', $post, $_product); ?>

<?php endwhile; ?>


  • Why can't you use in_category right there? – mrwweb May 18 '12 at 5:53
  • I tried sir, but the condition is not working <?php if (in_category('Lesson Pack')) { ?> <div id ="pack-desc" style="margin-top: 293px;"> <h2>Description</h2> <?php the_content();?> </div> <? } else { do_action('jigoshop_after_single_product_summary', $post, $_product ); } ?> please take a look sir, this product is in category "uncategorize" kjrias.com/store/metallica-enter-sandman while this product is in category "Lesson Pack" kjrias.com/store/lesson1 they are both using the "else" – markyeoj May 18 '12 at 6:33

Using in_category here is the correct function to use (it doesn't distinguish between post types).

The second argument accepted by in_category is the post ID or object - but in this case, can be omitted as we are using it inside the Loop.

The first argument is the Category ID (as an integer) or slug / name (as a string). Or alternatively an array of these. So make sure that 'Lesson Pack' is the name of the category (or else try using the slug, or the category ID).


As per comments, the plugin uses a custom taxonomy rather than the default category taxonomy. In that case, the function you should use is: has_term

 has_term('Lesson Pack', 'my-custom-taxonomy')

where the second argument is the name of the custom taxonomy.

  • Sir I already tried ID and Slug, and even using the post_is_in_descendant_category is also not working.. here is the edited code sir .. pastebin.com/MW2qazcL – markyeoj May 18 '12 at 10:34
  • Try listing the current post's category terms: <?php global $post; var_dump(get_the_terms($post->ID,'category'));?>. Are you using the default category taxonomy or a custom taxonomy? – Stephen Harris May 18 '12 at 10:42
  • That's a jigoshop's single-product.php template code and I'm pretty sure that they are using custom taxonomy. – markyeoj May 18 '12 at 10:47
  • Ah, in that case, see the edit :) – Stephen Harris May 18 '12 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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