Last active
September 23, 2017 16:26
-
-
Save vikrantnegi/0a6cbc327ba9d48481e899b13de6ee2b to your computer and use it in GitHub Desktop.
CPT Custom category
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment