Forums Forums Search Search Results for 'sf_input_object_pre function label'

Viewing 2 results - 61 through 62 (of 62 total)
  • Author
    Search Results
  • #40004

    Anonymous
    Inactive

    Perfect,

    I’ve done it… it works great. Thank you!

    For someone curious about how to implement this, on your plugin php add the following function:

    function my_plugin_search_filter_change_label($input_object, $sfid) {
      if ($sfid == 12345 && $input_object['name'] == '_sf_post_type') {
        foreach ($input_object['options'] as $key => $option) {
          if ($option->label == 'Media') {
            $input_object['options'][$key]->label = 'Photos';
          }
        }
      }
      return $input_object;
    }
    add_filter('sf_input_object_pre', 'my_plugin_search_filter_change_label', 10, 2);

    Hope it helps.

    #34366

    Ross
    Keymaster

    Hi Jacob sorry for the delay.

    You’re almost there.

    First, you have only 1 = in the first if statement.

    So it does the code for every single field – this needs to be changed to a double ==

    Second, I think likely you got the fieldname wrong – see here on how to get the correct fieldname:

    http://www.designsandcode.com/documentation/search-filter-pro/accessing-search-data/#How_to_get_the_field_name

    Here is your code updated (and I’m guessing the field name is from meta data, otherwise you need to find the name as link just above:

    <?php
    function filter_input_object($input_object, $sfid) {
    	
    	if(($input_object['name'] == '_sfm_workshop_location')) {
    		
    		foreach($input_object['options'] as $option) {
    			$option->label = get_the_title($option->value);
    		}
    		
    		return $input_object;
    	}
    	else {
    		
    		return $input_object;
    	}
    }
    add_filter('sf_input_object_pre', 'filter_input_object', 10, 2);
    
    ?>

    Thanks

Viewing 2 results - 61 through 62 (of 62 total)