Forums Forums Search Search Results for 'sf_input_object_pre'

Viewing 10 results - 111 through 120 (of 137 total)
  • Author
    Search Results
  • #80200

    Trevor
    Participant

    Are you saying that, on the S&F Pro form settings page, on the Posts tab, you tried it with the Primary sort as date and secondary sort as name? I would have thought that should have worked. as you say, there should be no need for the secondary sort, as the date would be sufficient.

    My initial though would be that you could code around this using one of our filters. See here in the documentation.

    If you use the filter sf_input_object_pre you get access to the options as an array, so you can order this array however you want, so you can use this to sort the array with php. But you would need to code this.

    #79998

    Trevor
    Participant

    See here in the documentation.

    If you use the filter sf_input_object_pre you get access to the options as an array, so you can order this array however you want.

    You Do have access to the count variable, so you can use this to sort the array with php. But you would need to code this.

    #76187

    In reply to: Default option on load


    Anonymous
    Inactive

    Hey Trevor,

    Thank you.

    After numerous other options I tried the below but not sure I’m in the right zone (the custom class is added to the field so it’s partly working).

    I just want to pull one of the options from that dropdown as the default on that page (selected option on page load).

    Any pointers?

    Thank you!

    <?php function filter_input_object($input_object, $sfid) {
    if ($input_object[‘name’] == ‘_sft_testcat’) {
    $input_object[‘defaults’] = array(“Test”);
    $input_object[‘attributes’][‘class’] = ‘mynew_class’;
    }

    return $input_object;

    }
    add_filter(‘sf_input_object_pre’, ‘filter_input_object’, 10, 2); ?>

    #73812

    Ross
    Keymaster

    Hey Ash

    The best way to get the current value is to use our active query class:

    https://www.designsandcode.com/documentation/search-filter-pro/accessing-search-data/

    Because you want the actual value it might be best to use the array method and pull your value from there.

    Alternatively, when using the sf_input_object_pre filter, the defaults should already be set to the current value from the URL, as its this default argument that is set by S&F and will be used to set the selected state.

    Doing a var_dump of $input_object['defaults'] should show the currently active value, if you access it at the top of your function before you’ve made any modifications (note: this will always be an array even for single selection type fields)

    Hope that makes sense?

    #70326

    Anonymous
    Inactive

    Looks like sf_input_object_pre only applies to text input field. How do I go about applying IDs or Classes to drop-down lists in the filter?

    #70150

    Trevor
    Participant

    Have you got switched ON (checked) the Maintain Search Form State setting? Try with it off if you have.

    For some fields, you can use the sf_input_object_pre filter, shown here (there is a link to an example usage code snippet as well):

    https://www.designsandcode.com/documentation/search-filter-pro/action-filter-reference/#Filter_Input_Object

    #69605

    Trevor
    Participant
    #66470

    Anonymous
    Inactive

    So here’s the complete solution to my situation – adding extra filtering to a S&F SQL query (using a S&F input field to pass the data) after the S&F does the initial SQL query using the rest of the input components in the S&F search form.

    /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
     * Modify the Search&Find SQL query using a S&F input component to pass values through.
     * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
    
    //First filter & modify the input field we're going to use so S&F will not use it for it's own query.
    //I used '_search-filter-settings' but you can use any meta_field in your WP DB.
    //Be sure to grab the field name from the <SELECT> element name in the form, OR add the prefix _sfm_ to the meta_key name.
    add_filter('sf_input_object_pre', 'mbs_alter_snf_field', 10, 2);
    function mbs_alter_snf_field($input_args, $sfid){
    	//+SET S&F FIELD TO USE
    	$mbs_snf_field='_sfm__search-filter-settings';
    
    	if(!isset($input_args['name']) || $input_args['name'] != $mbs_snf_field)
    		return $input_args;
    
    	$input_args['attributes']['name']='mbs'.$mbs_snf_field;
    	return $input_args;
    }
    
    //Secondly, filter & modify the S&F query after S&F did it's filtering based on the other search fields in the form.
    //Make changes to the WHERE clause of that resulting query, based on the input received from $mbs_snf_field input component.
    add_filter( 'posts_where' , 'mbs_posts_where_statement' );
    function mbs_posts_where_statement( $where ) {
    	global $wp_query;
    
    	//+SET FORM ID TO REACT UPON
    	$snf_form=345; 
    
    	//+SET S&F FIELD TO USE
    	$mbs_snf_field='_sfm__search-filter-settings';
    
    	//check if we're in Search context before altering the query
    	if ( $snf_form != $wp_query->query_vars['sfid'] ) return $where;
    
     	//check if this is a Search query or just displaying the search widget
     	if(strpos($where, 'mbs_posts.ID IN')===FALSE) return $where;
    
     	//check if the desired request field has been passed
     	if(!isset($_REQUEST['mbs'.$mbs_snf_field])) return $where;
    
     	//create a array and get values from it if the proper $_REQUEST isset, or default, so we only pass static data to SQL query.
     	$mbs_sql_range=array('10km'=>10,'15km'=>15,'20km'=>20,'25km'=>25,'50km'=>50);
     	$mbs_sql_range=(isset($mbs_sql_range[$_REQUEST['mbs'.$mbs_snf_field]])) ? $mbs_sql_range[$_REQUEST['mbs'.$mbs_snf_field]] : 50;
    
     	//alter the query
     	global $wpdb;
     	$where .= $wpdb->prepare(" AND $wpdb->posts.post_title LIKE '%%%s%%'",$mbs_sql_range) ;
     	
    	//removes the actions hooked on the '__after_loop' (post navigation)
    	remove_all_actions ( '__after_loop'); //* take this out if you don't need it.
     
    	return $where;
    }

    There is only one issue remaining, the input field used to pass the data, does not retain its selection when subsequently displaying the form. And that’s normal and not a very big issue.
    Ross, if you have some insight on this matter, that’ll be great!

    #64668

    Anonymous
    Inactive

    $searchandfilter worked in sf_input_object_pre.
    Form works as I expected now.

    #64663

    Anonymous
    Inactive

    Is this also work in sf_input_object_pre that you gave me?

    global $searchandfilter;
    $sf_current_query = $searchandfilter->get(1726)->current_query();

Viewing 10 results - 111 through 120 (of 137 total)