Forums › Forums › Search & Filter Pro › Precheck a box
Tagged: default option, precheck, preselect
- This topic has 3 replies, 2 voices, and was last updated 8 years, 9 months ago by Ross.
-
Anonymous(Private) January 20, 2016 at 1:20 am #34781
Hello is there a way to have an option checked by default?
So if I go to the page that has the search/filter on it, category 1 would be already checked and displaying results that only have category 1 checked?
Basically I have a subscription setup, and this plugin does a great job of allowing me to add subscription types using the post-meta but it only works if I click for example ‘subscription 1’ and returns results that are only available to that subscription type.
If only there was a way to have ‘Subscription 1’ prechecked, or even preselected as a dropdown. Either one would work.
Almost wrapped up the site but need this to work, Thanks a ton!
Ross Moderator(Private) January 20, 2016 at 8:21 am #34797Hey there
You can manually override the defaults supplied to any of your fields using a new S&F 2.1 filter
Check the devs section at the bottom for the github link:
http://www.designsandcode.com/33533/search-filter-2-1-released/
There are a ton of exmaples in there you won’t need, but what you will need for sure is this part:
$input_object['defaults'] = array("black");
This line sets the default, for checkboxes you can supply multiple values in the array to have multiple items checked.
The only other thing you will need to do is probably a check to see if a search form is actually empty, before applying your custom default array – you don’t want to overwrite a users’ selections, so first you must make sure there are no selections.
Check the active query class and
is_filtered
:
http://www.designsandcode.com/documentation/search-filter-pro/accessing-search-data/#Check_to_see_if_anything_has_been_filteredHope that helps!
Anonymous(Private) January 20, 2016 at 9:24 pm #34874This prechecked the box but it did not actually force the results to be correct. When I come onto the page if Category 1 has been force checked, it should only be showing those results initially… Any idea how to get this to work as expected?
Thanks a ton!
Ross Moderator(Private) January 21, 2016 at 8:04 am #34894Ah you also want the results to be reflected by the selection.
Currently there is no way to do this within the plugin.
The best bet you can do is link to the updated URL.
So, enable “bookmarkable URLs” (you can disable this later if necessary), then perform a search, selecting the first category, hit submit.
Notice the URL update to reflect this search.
In your navigation or wherever you link you search form, you can use this URL instead of the regular URL.
I’ve been thinking to add this kind of feature for quite some time.
Thanks
-
AuthorPosts