Problem:
For a Post View and/or Custom Search View, how can we exclude a taxonomy term from it using a filter hook?
Solution:
Method 1: Use the “Taxonomy filter” checkbox options in the View to exclude / include terms - screenshot here:
https://d7j863fr5jhrr.cloudfront.net/wp-content/uploads/2017/07/552238-Method_1.png?x71388
Method 2: Achieve this through code using 'wpv_filter_query' something like given below, please note you would need to modify it for your usage.
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.
Relevant Documentation:
- https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
- https://toolset.com/forums/topic/exclude-some-taxonomy-terms-from-filter-search/#post-204079
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 12:00 – 17:00 | 12:00 – 17:00 | 12:00 – 17:00 | 12:00 – 17:00 | 12:00 – 17:00 | - |
- | 18:00 – 21:00 | 18:00 – 21:00 | 18:00 – 21:00 | 18:00 – 21:00 | 18:00 – 21:00 | - |
Supporter timezone: Asia/Karachi (GMT+05:00)
This topic contains 5 replies, has 2 voices.
Last updated by 7 years, 3 months ago.
Assisted by: Noman.