Forums › Forums › Search & Filter Pro › way to filter out latitude/longitude/numerical values via Post Meta tab?
Tagged: post meta tab, V3
- This topic has 23 replies, 2 voices, and was last updated 5 years, 2 months ago by Trevor.
-
Trevor(Private) October 28, 2019 at 4:28 pm #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(Private) October 28, 2019 at 4:32 pm #224878Then 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(Private) October 28, 2019 at 4:43 pm #224882If 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(Private) October 28, 2019 at 4:50 pm #224890so 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? -
AuthorPosts