Forums › Forums › Search & Filter Pro › Customize Value Postfix
- This topic has 23 replies, 3 voices, and was last updated 5 years, 5 months ago by Anonymous.
-
Ross Moderator(Private) June 27, 2019 at 10:36 pm #215170
Hi 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.
Ross Moderator(Private) June 27, 2019 at 11:14 pm #215180Ah sure, then change the
foreach
loop to://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!=''){ $option->label .= " miles"; } }
-
AuthorPosts