WordPress.org

Ready to get started?Download WordPress

Forums

Excluding sub-categories from WP_Query (2 posts)

  1. jimmiejo
    Member
    Posted 5 years ago #

    I have a dozen or so different category templates for the different sections of my site, and am trying to exclude a few categories from one of them.

    Here's my loop:

    <?php $my_query = new WP_Query($query_string . "&cat=107,108,109,110&posts_per_page=16");
    		while ($my_query->have_posts()) : $my_query->the_post();
    		$wp_query->in_the_loop = true;
    		if ( $post->ID == $do_not_duplicate ) continue;
    		update_post_caches($posts);
    		$do_not_duplicate = $post->ID; ?>

    I've tried everything I could find/think of to either only include the four categories you see in the loop above (cat=107,108....) or exclude the others (cat=-112,-113...). Neither method seems to do anything, and I'm now thinking it's because all the categories are sub-categories of a main one, 105 in my case.

    Can you not exclude or only include sub-categories in a wp_query? Or is there another way to go about this?

    Thanks guys.

  2. Meitar
    Member
    Posted 5 years ago #

    I'm trying to do something similar and am running into what I think is the same exact problem. I've posted about it here but have yet to receive feedback. Maybe the answer to my question will also help you?

Topic Closed

This topic has been closed to new replies.

About this Topic