I have a theme with a portfolio page which allows me to exclude certain portfolio categories, by unchecking the categories i would like hide. (e.g Film, Art)
The problem is that certain portfolio items are assigned to multiple categories and my theme wont show the portfolio item if a category is unchecked but still is assigned to a category that is checked (so multiple categories).
How do i go about fixing this? I think i found the code in my functions file but im not certain.
I tried changing the operator from 'NOT IN' to 'IN' but this ends up showing all the cetegories. Any help would be greatly appreciated!
if ( isset( $cat ) && $cat!=-1 ) {
//include a category
$query_args['tax_query'] = array(
array(
'taxonomy' => PEXETO_PORTFOLIO_TAXONOMY,
'field' => 'slug',
'terms' => $cat
)
);
}
if ( !empty( $excludeCats ) ) {
if ( !isset( $query_args['tax_query'] ) ) {
$query_args['tax_query'] = array();
}
//exclude categories
$query_args['tax_query'][]= array(
'taxonomy' => PEXETO_PORTFOLIO_TAXONOMY,
'field' => 'id',
'terms' => $excludeCats,
'operator' => 'NOT IN'
);
}
I assume that the problem occurs on the portfolio archive. If this is the case, as a workaround I would suggest getting all the visible categories and adding them to the tax_query.
if( ! empty( $excludeCats ) ) {
$visibleCats = array_diff( $allCats, $excludeCats );
}
if ( !empty( $excludeCats ) ) {
if ( !isset( $query_args['tax_query'] ) ) {
$query_args['tax_query'] = array();
}
//exclude categories
$query_args['tax_query'][]= array(
'taxonomy' => PEXETO_PORTFOLIO_TAXONOMY,
'field' => 'id',
'terms' => $visibleCats,
'operator' => 'IN'
);
}