Tell us what you are trying to do?
hidden link
I have same view (view id: 56943) used multiple times on the same page. Each time i'm passing the category from which I want to show post. Example: wpvcategory="wheels". In the views setting, I'm using: "Categories slug in one of those set by the View shortcode attribute wpvcategory"
I've some posts that belong to two categories: 'Current Edition' as well as 'wheels'.
But i want to exclude those article which are in 'current edition'.
I could find similar answer here:
https://wordpress.stackexchange.com/questions/273523/include-posts-from-some-categories-while-excluding-from-others
But how do i do within views? Your help will be highly appreciated.
Hi there,
Thank you for contacting us and I'd be happy to assist.
To include an additional fixed taxonomy filter to exclude a specific term's posts, you can use "wpv_filter_query" filter:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
Example:
function filter_to_exclude_tax($view_args, $view_settings, $view_id) {
if (in_array($view_id, array(1234))) {
$view_args['tax_query'][] = array(
'taxonomy' => 'taxonomy-slug',
'field' => 'id',
'terms' => '56',
'operator' => 'NOT IN',
);
}
return $view_args;
}
add_filter('wpv_filter_query', 'filter_to_exclude_tax', 101, 3);
The above function can be included in the active theme's "functions.php" file and please replace:
- "1234" with the actual ID of your view
- "taxonomy-slug" with the actual slug of your target taxonomy ( e.g. "category" )
- "56" with the actual term's ID, that you'd like to exclude
I hope this helps and let me know if you need any further assistance around this.
regards,
Waqar
Thanks a lot, Waqar, for your kind help! Worked like charm. The said category is now excluded and it's exactly working the way i want it.