Forums Forums Search & Filter Pro Post Type ordering in Search Form

Viewing 6 posts - 1 through 6 (of 6 total)
  • Anonymous
    #230290

    Hi Trevor,

    I hope you’re well and Happy New Year!!

    Just a quick one, is there a way to order the Post Types list when using it as an option in the Search Form? Sadly it doesn’t seem like there is a way within the form creator, and I’m not sure what order it defaults to, but basically we need to change it to a custom order, as sadly if not we can’t use it, as the client really needs it to be a certain way.

    Is there a way I can control this, even if it’s custom code via functions?

    Sadly if not we are going to have to custom code the search form part, but really want to avoid that, as yours work so well :(.

    Thanks ever so much,
    TJ

    Anonymous
    #230291

    Oh and hello and Happy New Year to Ross too of course :)!!!!

    Ross Moderator
    #230320

    Hi Holly

    Happy new year to you 🙂

    You should be able to do this using our filter:
    https://searchandfilter.com/documentation/action-filter-reference/#filter-input-object

    This filter will allow you to modify all of the options (as an array) before its processed, this would be the base level code:

    function sf_do_something_with_options($input_object, $sfid){
    
    	//change '_sfm_my_field_name' to the name of your field
    	if($input_object['name']=='_sfm_my_field_name'){
    	
    		//return, if this field doesn't have an options array
    		if(!isset($input_object['options'])){
    			return $input_object;
    		}
    		
    		//to modify the options, we just need to update this array:
    		//$input_object['options'];
    		//so it can be rebuilt however you want, 
    		//use var_dump($input_object['options']) to check the format of the array
    
    	}
    	
    	return $input_object;
    }
    add_filter('sf_input_object_pre', 'sf_do_something_with_options', 10, 2);

    And to see more advanced maniuplation of the options array check:
    https://gist.github.com/rmorse/7b59b45a14b1ca179868

    I hope that helps!

    Anonymous
    #230451

    Hi Ross,

    Ahh thanks ever so much for this, that’s really helpful, going to have a play with this tomorrow :).

    Thank you again,
    TJ

    Anonymous
    #230570

    This works perfectly!! Thanks Ross :)!!!

    Ross Moderator
    #230676

    Great stuff 🙂

Viewing 6 posts - 1 through 6 (of 6 total)