Sauter la navigation

[Résolu] Hide empty filters

This support ticket is created Il y a 4 années et 10 mois. 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.

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: Asia/Karachi (GMT+05:00)

Ce sujet contient 3 réponses, a 2 voix.

Dernière mise à jour par romanB-3 Il y a 4 années et 10 mois.

Assisté par: Waqar.

Auteur
Publications
#1580045

Hi,
Thanks to Jamal, I was able to hide empty filters
https://toolset.com/forums/topic/hide-empty-filters/
But now the code don't work anymore, and I can't see why would that be!
I doubled check the #id is stille there, and the code didn't move either...
Thank you.

#1580047

Here is an example : lien caché
The filter "Publications" should have disappear !
Thank you.

#1581191

Hi Roman,

Thank you for contacting us and I'd be happy to assist.

I've checked the search form and noticed that the "Types of publications" and "Types of events" fields are still showing because their options are not empty.

One option with value '0' exists for both those fields.

Screenshot: lien caché

If you'd like to extend the custom script to hide these fields when only one option with 0 value exists, you can update it to:


jQuery(function($){
	$('#term-archive form select').each(function(){
		var select = $(this);
		var options = select.find('option')
	if ( ! options.length ) {
		select.parent().hide();
	}
	else if ( (options.length == 1) && (options.val() == 0) )
	{
		select.parent().hide();
	}
	})
})

I hope this helps and for more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

regards,
Waqar

#1581219

My issue is resolved now. Thank you very much!