exclude post from displaying in loop if it is in a category, but not in many categories

I am searching how to exclude posts from displaying in a loop if them are in a category x, but not in many categories…
The Problem: if I do exclude posts i.e. out of category 5, all posts are listed in category 5 will be excluded. Also those which are also in category 3 and 1.

how do i exclude:

while (have_posts()) : the_post(); 
  if(in_category($myCatsToExcludeArray)) continue;
  ...
  ... some general outputs
endwhile;

Related posts

1 comment

  1. All you’ll need to do is count() the get_the_category() results to determine how many categories your post is in, and check it along with your in_category().

    For example:

    while ( have_posts() ) : the_post();    
    if( in_category( $myCatsToExcludeArray ) && count( get_the_category( $post->ID ) ) == 1 ) {
    do something
    } 
    endwhile;
    

Comments are closed.