I've created a view (id 10410) and ive added a query filter to include specific taxonomies. I now want to add another query filter to exclude a single taxonomy (id 427). If I understand correctly I have to do it via a filter hook as the taxoniomy option is no longer available via the view interface since I've used it already. I've tried the following but with no luck
Thanks for you reply, but I dont see how using conditional output in the loop solves my issue. My loop query must show posts from category x AND exclude posts from category Y, not show either one or the other.
I have tried to use wpv_filter_query hook as below without success
‘exclude’ argument is not supported by WP anymore, you will need to use operator 'NOT IN' instead of exclude. There are 2 possible methods for this at moment
Method 1: Use the “Taxonomy filter” checkbox options in the View to exclude / include terms -- screenshot attached.
Method 2: Achive this entirely through code like given below, without any Taxonomy filter in the View.
add_filter( 'wpv_filter_query', 'exclude_terms_func', 10, 3 );
function exclude_terms_func($query, $setting, $views_ID)
{
if($views_ID == 3346) // your view id
{
$query['tax_query'][] = array(
'taxonomy' => 'book-author', // taxonomy name
'field' => 'slug',
'terms' => array( 'adam', 'adam2016' ), // term slug for exclude
'operator' => 'NOT IN'
);
$query['tax_query']['relation'] = 'AND';
}
return $query;
}
==> Whereas 'book-author' is the Taxonomy name and 'adam' is the slug of the term that you want to exclude.
We cannot use View filter and custom code over it at the same time, based on the information I have about your setup at moment. Thank you
Thank that query hook worked to exclude the required categories. I did use it i combination with the taxonomy filter in the view, which was set to include some category terms.
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.