-
AuthorSearch Results
-
December 11, 2018 at 5:55 am #195804
In reply to: Custom order of post meta options
AnonymousInactiveOk I got this working! Maybe not the best way possible but it works. Here is what I have done:
function filter_input_object($input_object, $sfid) { if(($input_object['name']!='_sfm_colors')||($input_object['type']!='select')) { return $input_object; } if(!isset($input_object['options'])) { return $input_object; } // Move Green To Top $key = array_search('Green', array_column($input_object['options'], 'value')); $top = $input_object['options'][$key]; unset($input_object['options'][$key]); array_unshift($input_object['options'], $top); // Move All Colors Back to Top $key1 = array_search('', array_column($input_object['options'], 'value')); $top1 = $input_object['options'][$key1]; unset($input_object['options'][$key1]); array_unshift($input_object['options'], $top1); return $input_object; } add_filter('sf_input_object_pre', 'filter_input_object', 10, 2);If there is a cleaner way I am interested, but this does work.
December 10, 2018 at 5:36 pm #195760In reply to: Custom order of post meta options
AnonymousInactiveNo that’s not the entire code i was using, I was trying to show the filter and function I was using to try and access the object value. I have based my attempts on this github code.
I have tried this:
function filter_input_object($input_object, $sfid) { if(($input_object['name']!='_sfm_colors')||($input_object['type']!='select')) { return $input_object; } if(!isset($input_object['options'])) { return $input_object; } foreach($input_object['options'] as $option) { $green = $option->value == 'Green'; } array_splice( $input_object['options'], 1, 0, array($green) ); return $input_object; } add_filter('sf_input_object_pre', 'filter_input_object', 10, 2);It returns blank
I just tried this:
function filter_input_object($input_object, $sfid) { if(($input_object['name']!='_sfm_colors')||($input_object['type']!='select')) { return $input_object; } if(!isset($input_object['options'])) { return $input_object; } $green = $input_object->value == 'Green'; array_splice( $input_object['options'], 1, 0, array($green) ); return $input_object; } add_filter('sf_input_object_pre', 'filter_input_object', 10, 2);It also returns blank
December 10, 2018 at 2:21 pm #195703In reply to: Custom order of post meta options
AnonymousInactiveYes. So for example, I am using:
function filter_input_object($input_object, $sfid) { if(($input_object['name']!='_sfm_colors')||($input_object['type']!='select')) { return $input_object; } if(!isset($input_object['options'])) { return $input_object; } } add_filter('sf_input_object_pre', 'filter_input_object', 10, 2);But when I try to access a specific option, I have not been able to do so with success. I am not sure of the array structure which is part of the issue.
November 8, 2018 at 1:28 pm #193165In reply to: ACF change date field output
AnonymousInactiveHi Trevor,
This is the code we’ve used btw. Maybe it’s useful 🙂
function filter_function_name($input_object, $sfid) { if($input_object['name']=='_sfm_kalender_datum') { foreach($input_object['options'] as $option) { if($option->value != "") { $date = strtotime( $option->label ); $option->label = date('d m Y', $date); } } } return $input_object; } add_filter('sf_input_object_pre', 'filter_function_name', 10, 2);August 30, 2018 at 11:37 am #186771In reply to: How to Change Form UI Labels
TrevorParticipantYou might be able to do this using our Input Object filter. This would allow you to remove the child terms, but you would need to write the code for that, using the code snippets linked to, or a search on our forum for other snippets that users may have posted:
https://support.searchandfilter.com/forums/search/sf_input_object_pre/
August 29, 2018 at 2:49 pm #186700
TrevorParticipantThe question about the URL modifier is not possible. You either stay on the shop page and have the two parts of the query, or it goes in to one of the category/taxonomy pages and has one query part.
as to the first question, you might be able to do this using our Input Object filter. This would allow you to remove the child terms, but you would need to write the code for that, using the code snippets linked to, or a search on our forum for other snippets that users may have posted:
https://support.searchandfilter.com/forums/search/sf_input_object_pre/
August 2, 2018 at 6:44 pm #184484Topic: Allow Blank Range Field
in forum Search & Filter Pro
AnonymousInactiveI have a range field with number inputs. I’ve figured out how to empty the default values out using the ‘sf_input_object_pre’ filter. However, when doing this I get 0 search results upon submitting the form. Basically, I’d like for this field to be optional. How can I achieve this?
July 17, 2018 at 2:11 pm #182762
AnonymousInactive@Trevor I think I am explaining it wrong. I am not looking to change to order of the posts, I want to change the order of a specific S&F filter that I created using the S&F admin tools which is a list of checkboxes.
This is what the field in S&F looks like

And here is the filter on the front end of my site

With CSS I already add icons for each item in the filter and that is the correct order. Now I need to hook in to the filter and change the order so that it is the same as in my admin, but I have no idea how to do that.
I think I need the
sf_input_object_prefilter and I already have this codefunction filter_function_name($input_object, $sfid) { if($input_object['name'] == '_sfm_category') { $input_object['attributes']['class'] = 'my-test-class'; return $input_object; } return $input_object; } add_filter('sf_input_object_pre', __NAMESPACE__ . '\\filter_function_name', 10, 2);It took me an hour to figure out how I would get this name
_sfm_categoryfrom my fieldcategory. It would be great if you could edit the docs and tell thereIf you are looking for your specific
$input_object['name']open your web inspector and look for the data attributedata-sf-field-name="_sfm_YOUR-FIELD-NAME"July 6, 2018 at 2:18 pm #182076In reply to: Infinite scroll not working on initial load
RossKeymasterHi Jane
Apologies for the delay – there’s been a good few things happenening and this slipped between the cracks.
In regards to your original problem, you were setting the second hidden date field with JS, and it was not being picked up properly on load more / pagination.
Well, we have a filter that allows you to set various attributes / values of each input field, via PHP (which I think may be more reliable):
https://searchandfilter.com/documentation/action-filter-reference/#filter-input-object
It actually gets a bit tricky targeting the second date field, as both the fields have the same name, so I did a little test and wrote this snippet which should work (add to functions.php):
add_filter('sf_input_object_pre', 'filter_input_object', 10, 2); global $from_to_field_count; $from_to_field_count = 0; function filter_input_object($input_object, $sfid){ //we need to target the second field with this name, $date_field_name = "_sfm_my_date_field"; if( $date_field_name === $input_object['name']){ global $from_to_field_count; $from_to_field_count++; if(2 === $from_to_field_count){ $input_object['attributes']['value'] = "29/07/2018"; } } return $input_object; }Make sure to replace
_sfm_my_date_fieldwith the name of your date field.Let me know how you get on!
Thanks
June 6, 2018 at 12:34 pm #179852In reply to: Removing "All Items" on Radio Button Post Meta
TrevorParticipantYou would need to code this yourself, but we have a filter for that:
It may be possible to do as you want with that. If you search our forum for
sf_input_object_preyou might find some helpful snippets, plus there is a link to some snippet code on Github in that documentation): -
AuthorSearch Results
Search Results for 'sf_input_object_pre'
-
Search Results
-
Topic: Allow Blank Range Field
I have a range field with number inputs. I’ve figured out how to empty the default values out using the ‘sf_input_object_pre’ filter. However, when doing this I get 0 search results upon submitting the form. Basically, I’d like for this field to be optional. How can I achieve this?