CPT Custom category
add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
if( is_category() ) {
$post_type = get_query_var('post_type');
if($post_type)
$post_type = $post_type;
else
$post_type = array('nav_menu_item', 'post', 'case_study'); // don't forget nav_menu_item to allow menus to work!
$query->set('post_type',$post_type);
return $query;
}
}
<?php if (have_posts()) : while (have_posts()) : the_post(); $post_type = get_post_type( get_the_ID() );
if ($post_type == 'case_study') ?>
<div class="col-sm-4 col-xs-12">
<a href="<?php the_permalink(); ?>" class="gallery-box">
<figure>
<?php the_post_thumbnail('medium', array('class' => 'gallery__img')); ?>
<figcaption class="gallery__caption">
<div class="gallery__caption-in">
<h3 class="gallery__tag"><?php the_title(); ?></h3>
<h4 class="gallery__intro"><?php the_excerpt(); ?></h4>
<img src="<?php echo get_template_directory_uri(); ?>/img/white-arrow.png" alt="" class="gallery__icon">
</div>
</figcaption>
</figure>
</a>
</div>
<?php endwhile; ?>
<?php endif; ?>