The forums are closed and will be removed when we launch our new site.
Looking for support? You can access the support system via your account.
-
AuthorSearch Results
-
September 28, 2020 at 7:39 pm #261160
In reply to: Reorder based on selection
TrevorModeratorThere ARE some shared snippets on the forum. Try this search:
https://support.searchandfilter.com/forums/search/sf_input_object_pre+function+order/
If you produce something, but it doesn’t quite work, by all means share the code for us to take a look at. Custom coding doesn’t really fall within the scope of our support, but we will help where we can.
September 25, 2020 at 10:57 am #260793In reply to: Pods Relationship Fields
RossKeymasterHi Sunny
You can replace the ID’s, by post title, by adding this to
functions.php
:function filter_input_object($input_object, $sfid) { if(($input_object['name'] == '_sfm_podsrelationship')) { 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);
Make sure to change the name of the field to match yours:
_sfm_podsrelationship
To find your field name, just check the URL when you do a search:
https://searchandfilter.com/documentation/accessing-search-data/?sfref=dc#how-to-get-the-field-nameLet me know how you get on.
Thanks
September 23, 2020 at 8:41 am #260434In reply to: Default value select
Paul KsiParticipanti`m using unset to delete first two option values but i need it to be default, how to do this?? thanks
function filter_function_name($input_object, $sfid)
{
if($input_object[‘name’]==’_sft_tax_news’)
{
/*foreach($input_object[‘options’] as $option)
{
if($option->value==”maironio-lietuviu-literaturos-muziejus”)
{
$option->label = “AAA”;
$option->attributes[‘class’] = “sf-option-active”;
$option->attributes[‘selected’] = “selected”;
}
}*/
unset($input_object[‘options’][0]);
unset($input_object[‘options’][1]);
return $input_object;
//udpate this field before rendering
}
else{
echo “NOOO!”;
return $input_object;
}
}
add_filter(‘sf_input_object_pre’, ‘filter_function_name’, 10, 2);filter_function_name(array(‘name’ => ‘_sft_tax_news’),17402);
September 22, 2020 at 2:11 pm #260342In reply to: Display custom query by default
TrevorModeratorYou can use this filter in your child theme’s functions.php file:
https://searchandfilter.com/documentation/action-filter-reference/#filter-input-object
To re-order the terms in that field.
I am not sure if it will help, but if there are any snippets already in the forum, this forum search should find them:
https://support.searchandfilter.com/forums/search/sf_input_object_pre+function+order/
September 10, 2020 at 12:09 pm #259039In reply to: How can I change categories or tags order?
TrevorModeratorWhat order would you like, or would it be entirely custom?
You may need to use this filter and your own custom code to do this:
https://searchandfilter.com/documentation/action-filter-reference/#filter-input-object
There are many snippets of code in this forum that use this filter. This forum search should show some of these:
https://support.searchandfilter.com/forums/search/function+sf_input_object_pre/
September 8, 2020 at 5:58 pm #258820In reply to: Prices – change ranges to custom
RossKeymasterI don’t have access to your site anymore, but this will replace all the optinos, with the 3 options you asked for:
function update_field_options($input_object, $sfid){ if( $input_object['name'] != '_sfm__price' ) { return $input_object; } // if we want to filter the options generated, we need to make sure the options variable actually exists before proceeding (its only available to certain field types) if( ! isset( $input_object['options'] ) ) { return $input_object; } // this is an array of all the options, we can remove them all, recreate them, etc $new_options = array(); // so create 3 options: $option1 = new StdClass(); $option1->value = "0+100"; $option1->label = "0 - 100"; array_push( $new_options, $option1 ); $option2 = new StdClass(); $option2->value = "100+250"; $option2->label = "100 - 250"; array_push( $new_options, $option2 ); $option3 = new StdClass(); $option3->value = "250+10000000"; $option3->label = "250 kr and up"; array_push( $new_options, $option3 ); $input_object['options'] = $new_options; return $input_object; } add_filter('sf_input_object_pre', 'update_field_options', 10, 2);
Thanks
September 2, 2020 at 2:09 pm #258119In reply to: Number Ranges Min-Max values
Nick SotiriadisParticipantSo, here is my code, don’t know how you want to make use for it, but here it is in case it helps someone!
First of all, I just set a couple of values in the admin, 0-100 – it makes no difference since I am unsetting the initial options anyway:
function change_car_engine_size($input_object, $sfid) { if($input_object['name']=='_sfm_car_engine_size') { unset($input_object['options']); $input_object['options']=array(); $arr = ['0','100','200','300','400', '500', '600', '700', '800', '900', '1000','2500','3000','3500','4000']; foreach ($arr as $value) { $new_option = new StdClass(); $new_option->value = $value; $new_option->label = number_format($value, 0, ',', '.'); array_push($input_object['options'], $new_option); } } return $input_object; } add_filter('sf_input_object_pre', 'change_car_engine_size', 10, 2);
August 28, 2020 at 9:32 am #257605In reply to: Prices – change ranges to custom
RossKeymasterHi Thomas
I just did a test, this code, replaces the 4 th option in a list, with what you mention:
function update_field_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 '_sft_post_tag' if( $input_object['name'] != '_sfm_price' ) { return $input_object; } // if we want to filter the options generated, we need to make sure the options variable actually exists before proceeding (its only available to certain field types) if( ! isset( $input_object['options'] ) ) { return $input_object; } // this is an array of all the options, we can remove them all, recreate them, etc // var_dump( $input_object['options'] ); // we know the option you want to replace is the 4th one in the list (including the default), so we can do : if ( isset ( $input_object['options'][3] ) ) { $new_option = new StdClass(); $new_option->value = "250+10000000"; $new_option->label = "250 kr and up"; $input_object['options'][3] = $new_option; } return $input_object; } add_filter('sf_input_object_pre', 'update_field_options', 10, 2);
That should get you going 🙂
Read the comments for a few clues.
Best
August 14, 2020 at 4:14 pm #256122
Nick SotiriadisParticipantFound it by investigating the inspector, but I think the name of each field should be more clearly visible.
Here is my working function:
function top_search_additional_attributes($input_object, $sfid) { if($input_object['name']=='_sf_search' && $sfid==161) { $input_object['attributes']['autocomplete'] = 'off'; $input_object['attributes']['autocapitalize'] = 'off'; $input_object['attributes']['autocorrect'] = 'off'; $input_object['attributes']['spellcheck'] = 'false'; echo $sfid; } return $input_object; } add_filter('sf_input_object_pre', 'top_search_additional_attributes', 10, 2);
June 30, 2020 at 9:16 am #250604In reply to: Total Count
RossKeymasterHi Maurino
We have a WP / PHP hook which you can use to modify each individual option in your field – you could then loop through all your options, count the total results, and add that to the first option (All Items) – this is the filter: https://searchandfilter.com/documentation/action-filter-reference/#filter-input-object
I’ve actually gone ahead and managed to create a code snippet for you that does this:
function add_count_to_first_option( $input_object, $sfid ) { // if the field doesn't have input options, then leave it alone if ( ! isset( $input_object['options'] ) ) { return $input_object; } $total_count = 0; // loop through each option and add up the total count foreach ( $input_object['options'] as $option ) { if ( isset( $option->count ) ) { $total_count += absint( $option->count ); } } // now check to make sure there was a first option (with value of "") // and update its count if ( isset( $input_object['options'][0] ) ) { if ( '' === $input_object['options'][0]->value ) { $input_object['options'][0]->label .= ' (' . $total_count . ')'; } } return $input_object; } add_filter('sf_input_object_pre', 'add_count_to_first_option', 10, 2);
Add this to your themes functions.php, and that will add a count to all first options in your fields.
Thanks
-
AuthorSearch Results