Forums Forums Search & Filter Pro Swap ACF Value and Label in filters

Viewing 5 posts - 1 through 5 (of 5 total)
  • Anonymous
    #253755

    Hi Trevor,

    How are you?
    Is it possible to create a hook that shows the html input value attributes in form labels instead of the label values, and adds the label value to a new or existing custom html attribute?

    This is for creating JS tooltips for filter values. I was making something with JS but this seems not possible because of the dynamic handling of item counting at the end of the label value.

    Thanks for thinking about this 🙂
    Roeland

    Trevor
    #253764

    The only hook we have is this, I don’t know if it will let you do what you want?

    https://searchandfilter.com/documentation/action-filter-reference/#filter-input-object

    Anonymous
    #254810

    Hi Trevor, thanks, I will try it now and let you know!

    Anonymous
    #254845

    It works perfect, thanks!

    
    if(!isset($input_object['options']))
    	{
    		return $input_object;
    	}
    	//now we know there are options we can loop through each one, and change what we need
    	foreach($input_object['options'] as $option)
    	{
            if($option->value=="")
    		{//the option with no value is always the "all items" or unselected state
    			
    		}
            else
    		{//we want to change the label for the option "black" - we can feed back in the count number to the label for this field type
                $option->attributes['title'] = $option->label;
                $option->label =  $option->value ." (".$option->count.")";
    		}
    	}
    
    Trevor
    #254853

    Thanks for getting back to me and sharing your solution. I will close this thread for now.

Viewing 5 posts - 1 through 5 (of 5 total)