Blank options appear in search filter

Forums › Forums › Search & Filter Pro › Blank options appear in search filter

Viewing 8 posts – 11 through 18 (of 18 total)
  • Anonymous
    #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
    #272280

    Hi Keith

    We have a filter here for modifying all input fields:
    https://gist.github.com/rmorse/7b59b45a14b1ca179868

    Essentially, 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

    Anonymous
    #272376

    Ross,

    Thank you! This works perfectly.

    How would I edit it to make the filter work on multiple fields? I’d want to apply it for the following fields:

    _sfm_practice_areas, _sfm_industries and _sfm_attorneys

    Ross Moderator
    #272517

    Hey 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

    Anonymous
    #272579
    This reply has been marked as private.
    Ross Moderator
    #272974
    This reply has been marked as private.
    Anonymous
    #276865
    This reply has been marked as private.
    Trevor
    #276867

    Hi Keith

    These forums are now closed for support. Could you open a ticket, either in Your Account on our website, or by email to [email protected]

    (It might help to mention your licence key number if our system cannot find you)

Viewing 8 posts – 11 through 18 (of 18 total)

Search & Filter Support
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

We also use cookies to store items in your cart as well as allowing your to login on the site.

You can adjust all of your cookie settings by navigating the tabs on the left hand side.

By continuing to use this site, you also agree to our Privacy Policy.