Support

Account

Home Forums General Issues filter relationship query – exclude if a certain category Reply To: filter relationship query – exclude if a certain category

  • If I understand you want to include posts that are in 2 categories but exclude them if they are also in a third category.

    I.E. Show if in category 76 but not if it is also in category 78.

    I think that in order to do this you need to use a tax_query. I could be wrong but I do not think the ‘cat’ argument can be used the way you are trying to use it and I also thing that using ‘category__in’ combined with ‘category__not_in’ will work the same way. Like I said, I could be wrong but I think these arguments work as ‘OR’ (meaning category 76 OR not category 78).

    
    $args['tax_query'] = array(
      'relation' => 'AND',
      array(
        'taxonomy' => 'category',
        'field' => 'term_id'
        'terms' => array(76, 77),
        'operator' => 'IN'
      ),
      array(
        'taxonomy' => 'category',
        'field' => 'term_id'
        'terms' => array(78),
        'operator' => 'NOT IN'
      )
    );