WP Query – How To Change The Relationship Between Each Inner Taxonomy Array

How can I make this category post filter to have an (AND) logical relationship between each individual category?

$categories = get_query_var(‘selected-white-papers-categories’);
$tax_query = array();

if ( ! empty( $categories ) ) {
$tax_query[] = array(
‘taxonomy’ => ‘white-papers-categories’,
‘field’ => ‘term_id’,
‘terms’ => explode( ‘-‘, $categories ),
‘operator’ => ‘IN’
);
}

if ( count( $tax_query ) > 1 ) {
$tax_query[‘relation’] = ‘OR’;
}

Read more here:: WP Query – How To Change The Relationship Between Each Inner Taxonomy Array

Leave a Reply

Your email address will not be published. Required fields are marked *