Forums › Forums › Search & Filter Pro › Post Type ordering in Search Form
- This topic has 5 replies, 2 voices, and was last updated 4 years, 11 months ago by Ross.
-
Anonymous(Private) January 7, 2020 at 9:17 am #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,
TJRoss Moderator(Private) January 7, 2020 at 1:55 pm #230320Hi 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-objectThis 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/7b59b45a14b1ca179868I hope that helps!
-
AuthorPosts