Forums › Forums › Search & Filter Pro › Blank options appear in search filter
- This topic has 17 replies, 3 voices, and was last updated 1 year, 3 months ago by Trevor.
-
Anonymous(Private) January 7, 2021 at 2:31 pm #271931
Ross,
I just checked those two news article links and they seem to be working fine for me. Not sure why you were seeing a 404 error on those, but that shouldn’t have been the case.
What steps do we need to take you write the code to hide the blank options?
Ross Moderator(Private) January 11, 2021 at 9:17 am #272280Hi Keith
We have a filter here for modifying all input fields:
https://gist.github.com/rmorse/7b59b45a14b1ca179868Essentially, the only part you need from that is you need to loop through the options:
function remove_empty_options($input_object, $sfid ) { //ensure we are only filtering the correct field name - in this case the field we want to filter has the name <code>_sfm_attorneys</code> if(($input_object['name']!='_sfm_attorneys')){ return $input_object; } if(!isset($input_object['options'])) { return $input_object; } $new_options = array(); foreach($input_object['options'] as $option) { if ( trim( $option->label ) !== '' ) { array_push( $new_options, $option ); } } $input_object['options'] = $new_options; return $input_object; } add_filter('sf_input_object_pre', 'remove_empty_options', 10, 2);
I haven’t actually tested this, but it looks to be correct.
You will need some PHP development skills to modify – that should go in your child themes
functions.php
.Best
Ross Moderator(Private) January 12, 2021 at 3:20 pm #272517Hey Keith
So you would change:
if(($input_object['name']!='_sfm_attorneys')){ return $input_object; }
to:
$allowed_fields = array( '_sfm_practice_areas', '_sfm_industries', '_sfm_attorneys' ); if ( ! in_array( ($input_object['name'], $allowed_fields ) ) { return $input_object; }
Thanks
Trevor(Private) September 19, 2023 at 10:17 pm #276867Hi Keith
These forums are now closed for support. Could you open a ticket, either in Your Account on our website, or by email to support@searchandfilter.com
(It might help to mention your licence key number if our system cannot find you)
-
AuthorPosts