Support Forums

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.

Forums Forums Search Search Results for 'sf_input_object_pre'

Viewing 10 results - 91 through 100 (of 150 total)
  • Author
    Search Results
  • #199420

    Trevor
    Moderator

    If you mean how they display in the dropdown select in the form, you would need to do this using our https://searchandfilter.com/documentation/action-filter-reference/#filter-input-object filter.

    I do not know if there are any snippets showing how other users have done anything similar, but you might find the posts that this search returns useful:

    https://support.searchandfilter.com/forums/search/sf_input_object_pre+sort/

    #196334

    James Piper
    Participant

    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,
    Kota

    #195804

    Matt Harris
    Participant

    Ok 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.

    #195760

    Matt Harris
    Participant

    No 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

    #195703

    Matt Harris
    Participant

    Yes. 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.

    #193165

    Stijn De Witte
    Participant

    Hi 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);
    #189570

    Ross
    Keymaster
    This reply has been marked as private.
    #188497

    Eduardo Scherer
    Participant
    This reply has been marked as private.
    #186771

    Trevor
    Moderator

    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/


    Trevor
    Moderator

    The 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/

Viewing 10 results - 91 through 100 (of 150 total)