Skip Navigation

[Resolved] One Checkbox as search

This thread is resolved. Here is a description of the problem and solution.

Problem:
How can I create a checkbox, which when checked returns all results matching that value?
I want only one checkbox, not several values.
When that checkbox is checked, the results are filtered.
If it's not checekd, it's not filtered.

Solution:
Create a single Checkbox field and choose to save nothing in the database if not set.

Head to your posts who should be "yes" and update that Checkbox (check it)

In a View create a Custom Filter for that Field and choose as output "Single Checkbox".

That will produce a single Checkbox, unchecked by default, that the user can check, and it will then display only those posts with "yes" saved.

This support ticket is created 6 years, 11 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 4 replies, has 2 voices.

Last updated by chrisS-18 6 years, 10 months ago.

Assisted by: Beda.

Author
Posts
#614709
Screen Shot 2018-02-09 at 11.16.53 AM.png

Hi there - I have a View that searches a variety of fields. One of the fields "Accredited" is either "yes" or "no" for each entry.

I need a checkbox search filter that says "Check here to include only Accredited Courses" which would then return only entries that have "yes" in the Accredited field.

Currently the filter on that field shows both options "yes" and "no" but that isn't what we need.

thanks

#614818

Well, since 2 values are stored, Views properly will produce 2 values to choose from.
The right approach would be to store the data in a way that matches the expected output.

I would need to know what nature the Custom Field is of.
In Toolset > Post Fields > Edit your Field group > your Field. What is the type of this field?

If it's a Checkboxes Field, or several Checkbox Fields, or a simple single line matters later on what we can do with it.

According your description I am confused because you mention it can either be this or that, but Checkboxes allow several values at the same time, hence eventually your backend field is a radio field?

Please can you let me know how this exactly looks?

It also depends if you use AJAX updated Search, or a manual submitted search with a Search Button.
Depending on this we can produce a simple HTML input that you can code into the filter HML section.
With this you would additionally filter out certain items.

I need to know more details on the below list to proceed:
- what type is the field of?
- are you using AJAX in the View?
- what are the values stored for "yes" and "no", and how should they be visible in the search?

#615460

Hi Beda - thanks for your speedy reply.

I have the Accredited (yes/no) in two places: as a Category with "Accredited" as the parent and Yes and No as children. Also I have it as a Single Line field. I imported the values as "yes" and "no". The current filter is using the Single Line field.

I do have it set up as an Ajax right now, but can change it if that helps.

In the search I want one checkbox that says: "Check to include only Accredited courses". It would return only courses with "yes" in either the Accredited single line field or child category.

thanks again

#615598

It's not necessary to save this information in so many places, in such a nested way.

Just create a single Checkbox field and choose to save nothing in the database if not set.

Head to your posts who should be "yes" and update that Checkbox (check it)

In the view create a Custom Filter for that Field and choose as output "Single Checkbox".
That will produce a single Checkbox, unchecked by default, that the user can check, and it will then display only those posts with "yes" saved.

#615746

Thank you, Beda!

How is that I've been using Toolset very regularly for 3 years and never saw the single checkbox field type? I only ever noticed the multiple checkboxes.

Problem solved.

Have a great day,
Chris