Home › Toolset Professional Support › [Resolved] Hide empty filters
Problem:
The user would like to hide a filter when the visible results do not have a filter term assigned
Solution:
jQuery(function($){ $('#term-archive form select').each(function(){ var select = $(this); var options = select.find('option') if ( ! options.length) { select.parent().hide() } }) })
Notice:
Depending on how you are creating your forms, labels, controls, etc... the Javascript code might need to be adapted. In this example, we used the id "term-archive" and we hide the parent form-group of the filter(select)
Relevant Documentation:
https://toolset.com/documentation/user-guides/views/front-page-filters/advanced-settings-custom-search/
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.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | - | - | 9:00 – 13:00 |
14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | - | - | 14:00 – 18:00 |
Supporter timezone: Africa/Casablanca (GMT+01:00)
Tagged: Custom search, Views plugin
Related documentation:
This topic contains 3 replies, has 2 voices.
Last updated by romanB-3 4 years, 7 months ago.
Assisted by: Jamal.
Hello,
I have an Archive page with 4 taxonomy filters displayed on frontend.
Most of terms displayed with this Archive page only have some of those taxonomies, and not all of them.
I would need the filters to display only if there is at least one term for the taxonomy.
Please see an example here : hidden link
Thank you.
Hello and thank you for contacting the Toolset support.
You will need to customize the search setting of your view similar to this screenshot https://toolset.com/wp-content/uploads/2018/10/1132932-Screenshot_2018_10_23_at_10.05.17_AM.png
That way you can choose to hide/deactivate the filters when there are no terms on the results.
https://toolset.com/documentation/user-guides/views/front-page-filters/advanced-settings-custom-search/
I hope this helps. If it does not, please allow me temporary access to your website to check this further. Your next reply will be private to let you share credentials safely.
** Please make a database backup before sharing credentials **
The settings that I suggested affect the filter in a way that no terms that are not on the results will be on the filter control, but it does not hide the control itself. For that, I added a Javascript code and an id to the column of the filters to be able to hide the controls that do not have any result assigned to their terms.
jQuery(function($){ $('#term-archive form select').each(function(){ var select = $(this); var options = select.find('option') if ( ! options.length) { select.parent().hide() } }) })
I already updated your view. Please check if this produces what would you expect.
That is awesome !!
Thank you very much !!