Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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; ?>
        </div>
        <?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>

        <!--IF POST BELONGS TO CATEGORY "PACKAGE"-->
        <div id ="pack-desc" style="margin-top: 293px;">
        <h2>Description</h2>
        <?php the_content();?>
        </div>
        <!--ELSE-->
        <?php do_action('jigoshop_after_single_product_summary', $post, $_product ); ?>
        <!--END IF-->

    </div>

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

<?php endwhile; ?>
?>

thanks

share|improve this question
    
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

1 Answer 1

up vote 1 down vote accepted

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).


Edit

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.

share|improve this answer
    
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
    
Thank you so much sir :) works like charm .. –  markyeoj May 19 '12 at 8:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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