Hello there,
I have part of my problem solved already using the code below which hides the taxonomy from the view results:
// Exclude cats from search
add_filter( 'wpv_filter_query', 'exclude_terms_func', 10, 3 );
function exclude_terms_func($query, $setting, $views_ID)
{
if($views_ID == 182) // your view id
{
$query['tax_query'][] = array(
'taxonomy' => 'things-to-do-category', // taxonomy name
'field' => 'slug',
'terms' => array( 'professional-services', 'other-professional-services' ), // term slug for exclude
'operator' => 'NOT IN'
);
$query['tax_query']['relation'] = 'AND';
}
return $query;
}
HOWEVER, it's still appearing in the actual Views Filters (a SELECT dropdown). Is there a slight reworking of the above/ other function code that would acheive this?
I've already tried wrapping the filter in code with a conditional statment but this doesnt work.
Hi, there's no PHP API to filter the filter options, so I think you would be limited to a custom JavaScript approach here. You could remove term options programmatically using jQuery if you're comfortable writing your own JS code. We have a couple of event hooks that could be useful. In the View editor, find the Search and Pagination editor panel. Expand the JS editor area and you'll see a front-end events button. Click there and the system will generate event hooks you can use to trigger your own JavaScript code. You could use jQuery's attribute value selectors to target options with specific values, and remove them from the DOM whenever the results are updated, or the filters are changed, and so forth, based on those event hooks you set up. Let me know if you have questions about implementing those event handlers.
Here's a code snippet showing an example of removing an option with an attribute value selector:
jQuery('.some-select-class option[value="12345"]').remove();
Ok thanks for your input - I had indeed looked at that option however wanted something more toolset based.
May I suggest possibly putting this to the Toolset Devs. I think having better control built in over filtering taxonomies would be useful to many.
Thanks
Paul
Yes, you can add a suggestion for improvement over here: https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/
That's the best way to get your request to those in charge of feature development. Thanks for your input!