-
Search Results
-
Topic: Not working on page load
Hello Team,
No matter where I search, I can’t find a way to make the plugin run on page load.
Once I start clicking around, the ajax filtering works fine, but I need it to work on the first page load too.
We are using the code below to remove one of the options and to set the default active item. This all works fine.
// Remove “All Courses” option and set main to default on Our Menu.
add_filter( ‘sf_input_object_pre’, function ( $input_object, $sfid ) {
if ( $sfid == 120 ) {
// var_dump($input_object);
if ( ( $input_object[‘name’] = ‘_sft_course’ ) ) {
if ( empty( $input_object[‘defaults’][0] ) ) {
$input_object[‘defaults’] = [ ‘main’ ];
}
$key = array_search( ‘All Courses’, array_column( $input_object[‘options’], ‘label’ ) );
if ( $key !== false ) {
unset( $input_object[‘options’][ $key ] );
$input_object[‘options’] = array_values( $input_object[‘options’] );
}
}
}return $input_object;
}, 10, 2 );Can you please tell me how to instruct the plugin to run in the fresh page load?
I can’t find the answer anywhere in the docs or internet.Thank you very much,
KotaTopic: No longer searching
All of a sudden the search forms have stopped sorting. The page is here: https://intrepidexposures.com/photo-tours/
Tweaks to code as per previous threads here:
// Search Filter function filter_input_object($input_object, $sfid) { if(($input_object['name'] == '_sfm_workshop_location') || ($input_object['name'] == '_sfm_tour_style') || ($input_object['name'] == '_sfm_tour_leader')) { $new_options = array(); //the options added to this will replace all existing optoins in the field foreach($input_object['options'] as $option) { if ($option->value !== "") { //check to see if the option has a parent $parent_id = wp_get_post_parent_id($option->value); if(!$parent_id) { //then this option does not have a parent, so it must be a parent itself, add it to the new array $option->label = get_the_title($option->value); array_push($new_options, $option); } } } //now we have an array with only parent options in, so simply replace the one in the input object $input_object['options'] = $new_options; } return $input_object; } add_filter('sf_input_object_pre', 'filter_input_object', 10, 2);Any ideas?
Topic: Set selected item on filter
I’m trying to set dropdown options programmatically.
But all of options on dropdown come out with “selected” attribute.
How do I set selected attribute properly to single option currently selected?function sf_input_object_pre_mod($input_object,$sfid){ if($sfid==123){ if($input_object['name']=='_sfm_event_month'){ $mons[] = date('Y-m', strtotime(date('Y-m-01'))); for($i=1;$i<=11;$i++){ $mons[] = date('Y-m', strtotime(date('Y-m-01').' +'.$i.' month')); } foreach($mons as $k=>$m){ $opt = new StdClass(); $opt->label = $m; $opt->attributes = array('class'=>'sf-level-0'); $opt->values = $m; $opt->count = 0; $input_object['options'][] = $opt; } } } return $input_object; } add_filter('sf_input_object_pre','sf_input_object_pre_mod',10,2);I recently upgraded to the latest version and now it is calling an error. Any ideas?
function filter_input_object($input_object, $sfid) { if(($input_object['name'] == ('_sfm_workshop_location' || '_sfm_tour_style' || '_sfm_tour_leader'))) { foreach($input_object['options'] as $option) { if ($option->value !== "") { $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);