Forums › Forums › Search & Filter Pro › Customize Value Postfix
- This topic has 23 replies, 3 voices, and was last updated 6 years ago by
Anonymous.
-
Trevor(Private) June 25, 2019 at 7:00 pm #214935
Spotted another errod, sorry.
function add_miles_to_filter_labels($input_object, 2116) { if($input_object['name']!='_sfm_distance[]') { return $input_object; } foreach($input_object['options'] as $option) { $option->label .= " miles"; } return $input_object; } add_filter('sf_input_object_pre', 'add_miles_to_filter_labels', 10, 2);
Trevor(Private) June 27, 2019 at 4:32 pm #215141I had a thought. Try this:
function add_miles_to_filter_labels($input_object, $sfid) { if(($input_object['name']!='_sfm_distance[]'||($sfid != 2216)) { return $input_object; } foreach($input_object['options'] as $option) { $option->label .= " miles"; } return $input_object; } add_filter('sf_input_object_pre', 'add_miles_to_filter_labels', 10, 2);
Ross Moderator(Private) June 27, 2019 at 10:36 pm #215170Hi Andrew
Your link went offline so I couldn’t see. I’m guessing you tried something like the following section of code (this adds a prefix / postfix outside the select field itself).
Also, notice the
name
doesn’t have the brackets_sfm_distance
:function filter_input_object($input_object, $sfid){ if(($input_object['name']!='_sfm_distance')){ return $input_object; } //add/override prefix & postfix to the field $input_object['prefix'] = "Prefix "; $input_object['postfix'] = " Postfix"; return $input_object; } add_filter('sf_input_object_pre', 'filter_input_object', 10, 2);
However if you wanted to change the labels (or in this case append text to it) it would be like:
function filter_input_object($input_object, $sfid){ if(($input_object['name']!='_sfm_distance')){ return $input_object; } //if we want to filter the options generated, we need to make sure the options variable actually exists before proceeding (its only available to certain field types) 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){ $option->label .= " miles"; } return $input_object; } add_filter('sf_input_object_pre', 'filter_input_object', 10, 2);
Thanks
PS – I’ve actaully tested both of these just now with my own field, so there shouldn’t be syntax errors.
-
AuthorPosts