Forums Forums Search & Filter Pro way to filter out latitude/longitude/numerical values via Post Meta tab?

Tagged: ,

Viewing 10 posts - 11 through 20 (of 24 total)
  • Anonymous
    #224871

    the ID of the form is 23 and the field name is _location

    Trevor
    #224875

    So, something like this:

    function filter_location($input_object, $sfid)
    {
    	if(($input_object['name']=='_sfm_location') && ($sfid=="23"))
    	{
    		//udpate this field before rendering
    	}
    	
    	return $input_object;
    }
    add_filter('sf_input_object_pre', 'filter_location', 10, 2);
    Anonymous
    #224878

    Then how do I apply this filter? Or will it just work automatically? Sorry, filters and hooks are something I’m still getting used to.

    Also, do you accept tips? LOL. You are awesome for working through all my questions with me Trevor. I really appreciate your patience.

    Trevor
    #224882

    If that code (plus whatever you put in the middle) is in the child theme (note it should be a child theme, and NOT a parent them, unless you wrote the parent theme) functions.php, everytime a page loads in your site, that functions.php file is executed.

    It gets to the add_filter and code in our plugin knows what to do with that, and our plugin then runs the function for each form on the page. As it does so it fetches the form ID and a list of the fields in the form (the input object). It does this each field at a time.

    Our plugin passes the array relating to each input field (values, labels, etc) to the function. When, in my code, it matches the form to ID 23 and matches the field to _sfm_location (which, if you inspect the form you will see is the name our plugin has given that custom field’s input object), only then does it run the code in the middle. In all cases, the modified or unmodified input_object array is passed back to the form.

    After that,

    Anonymous
    #224884

    Okay got it! That makes sense. thank you for your help!

    Trevor
    #224888

    Great. Let me know how you get on?

    Anonymous
    #224890

    so here is my testing filter:

    function filter_lat_long($input_object, $sfid) {	
    	if(!isset($input_object['options']))
    	{
    		return $input_object;
    	}
    	
    	if(($input_object['name']=='_sfm_location') && ($sfid=='23')) {
    		
    		foreach($input_object['options'] as $option) {
    			
    			$option->value =  'Hello';
    			
    		}
    	}	
    	return $input_object;
    }
    add_filter('sf_input_object_pre', 'filter_lat_long', 10, 2);

    however, $option->value = "Hello"; is not changing the options to “Hello” in the form. what am I missing here?

    Trevor
    #224892

    Are you able to send me a live link/URL to your search page so I can take a look?

    Anonymous
    #224901

    I can’t unfortunately, as it’s a private work project.

    If I do a var_dump of $option->value, it shows the values as being changed to “Hello”. But the search form still shows the old values.

    Trevor
    #224903

    I think you should be changing the label, not the value?

Viewing 10 posts - 11 through 20 (of 24 total)