exclude categories from wp_query with get_the_category
I would appreciate some help here. below is what I have so far. I have a custom post type (projects) and I’m using this code to get the current category. The problem is that it gets the first category that the post is in so if it’s in ‘featured items’ for example it will display all the posts in that category rather than ‘houses’ which is the current category.
I suppose I’m looking for a way to exclude some categories. Does anyone have a solution?
<?php global $post; $categories = get_the_category(); $category = $categories; $cat_ID = $category->cat_ID; $custom_query = new WP_Query( array( 'post_type' => 'projects', 'cat' => $cat_ID ) ); ?> <?php while($custom_query->have_posts()) : $custom_query->the_post(); ?>
Thanks in advance
- The topic ‘exclude categories from wp_query with get_the_category’ is closed to new replies.