Skip Navigation

[Resolved] Exclude Taxonomy from View Filters

This support ticket is created 4 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

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.

Our next available supporter will start replying to tickets in about 2.34 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 3 replies, has 2 voices.

Last updated by Christian Cox 4 years, 7 months ago.

Assisted by: Christian Cox.

Author
Posts
#1332529

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.

#1332879

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();
#1333233

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

#1334459

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!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.