Forums › Forums › Search & Filter Pro › Change default selection of checkbox filter
Tagged: V3
- This topic has 2 replies, 2 voices, and was last updated 4 years, 2 months ago by Anonymous.
-
Anonymous(Private) November 11, 2020 at 3:36 pm #266046
I am trying to change the default landing state of a page from ‘all’ to a sepcific category or value. (i.e education) I am using a shortcode and am customising the php file. I am using a custom field of ‘projects’ and filtering these using a checkbox filter by ‘project-type’ (eg. education, commercial etc.)
Reading through the forum I think I need to use a combination of these three snippets but cannot put them together. Can anyone help out?
1.
function filter_function_name($input_object, $sfid)
{
if($input_object[‘name’]==’_sft_project-type’)||($input_object[‘type’]!=’select’))
{
//udpate this field before rendering
}return $input_object;
}
add_filter(‘sf_input_object_pre’, ‘filter_function_name’, 10, 2);2.
$input_object[‘defaults’] = array(“education”);
3.
//Get an array of objects containing data for the current search/filter
//replace1526
with the ID of your search form
global $searchandfilter;
$sf_current_query = $searchandfilter->get(43)->current_query();
echo $sf_current_query->is_filtered();Trevor(Private) November 11, 2020 at 4:36 pm #266082I agree with the logic, and indeed I have tried to do this myself as the solution to this same question by other users previously. It should work, but it does not, sadly.
Setting a default value is not possible with the current version of the plugin, but is something we intend to add in V3, due in a few months.
-
AuthorPosts