WordPress.org

Ready to get started?Download WordPress

Forums

exclude categories from wp_query with get_the_category (1 post)

  1. stickybeak
    Member
    Posted 2 years ago #

    Hi,

    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[0];
    $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

Topic Closed

This topic has been closed to new replies.

About this Topic