Skip Navigation

[Résolu] Parametric Search: Display results ONLY if all check boxes are present in field.

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:
How to create parametric search view with filter checkbox selected by default

Solution:
To create parametric search you should refer to our complete documenation here:
=> https://toolset.com/documentation/user-guides/front-page-filters/

To set checkbox checked by default you need to add jQuery custom code:

jQuery(document).ready(function($){
  $(".wpcf-form-item-checkbox :checkbox").prop("checked", true);
});

Relevant Documentation:
https://toolset.com/documentation/user-guides/filtering-views-by-taxonomy/
https://toolset.com/documentation/user-guides/passing-arguments-to-views/

This support ticket is created Il y a 8 années et 2 mois. 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Marqué : 

This topic contains 8 réponses, has 2 voix.

Last updated by peterH-7 Il y a 8 années et 2 mois.

Assisted by: Minesh.

Auteur
Publications
#365789

Ok, so I am trying to make a parametric search on my site which displays recipes. I have a bunch of data which includes recipe name and ingredients. I have made a custom post type called Recipes which has this data in custom fields. The ingredients are in a repeater field (single line text). There is only 4 ingredients or less per recipe.

Now I want to make a "recipe finder" page which basically has a parametric search feature so that users can tick which ingredients they have at home and then the view will display a list of recipes which match ALL of their ingredients. By default the views parametric search can filter the results of the view by ingredient but it does not check to see if the recipe ingredients match ALL of the checkboxes filled in by the user.

So this means, for example, if there are lots of recipes with "fish" as an ingredient the view will display all of these results as soon as a user check the "fish" box. What I want is to display only results with match ALL of the check boxes ticked by the users and none of the results which only match SOME of the boxes ticked.

I'm not sure if this is possible, however, I though I would try. Is the repeater the best field for this kind of use?

#365811

Minesh
Supporter

Languages: Anglais (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

As I understand you want to different set of data that belongs to your post so I suggest you should create a different custom field or taxonomy for ingredients and then, later filter your view with the custom field with "And" or "OR" as required.

Following links may help you:
=> https://toolset.com/documentation/user-guides/front-page-filters/
=> https://toolset.com/documentation/user-guides/filtering-views-by-taxonomy/
=> https://toolset.com/documentation/user-guides/passing-arguments-to-views/

#365818

Thanks, I've had a read through those links but I'm still unsure. I have a custome field for ingredients, and I have a filter to make checkboxes for this custom field. I need the checkboxes to use AND though. So I can tick for example "chicken" and "garlic" and this filters it for recipes which have ONLY "chicken" and "garlic" but nothing else. At the moment the filter allows things which have just one of "chicken" or "garlic" even though they also have other ingredients which are not ticked in the checkboxes.

Edit: I'm going to try filtering by taxonomy tomorrow, as maybe this will solve it and let it behave how I am looking for.

#365887

Minesh
Supporter

Languages: Anglais (English )

Timezone: Asia/Kolkata (GMT+05:30)

please let me know the result how it goes with taxonomy.

#365914

So I haven't fully tried taxonomy yet, although I'm not sure it would work.

Is there any way to achieve the following:

On the view front end, before displaying a post (Recipe) first check the state of the filter checkboxes (my filters). So I would have it check the checkboxes and IF my custom field (ingredients) is NOT checked, then don't display the post. So if ANY ingredient is NOT checked in the checkboxes the entire Recipe would not be displayed in this view. Put another way: all values of the ingredient custom field MUST be checked before the post is displayed - if one ingredient is not checked then the post is not displayed in the view.

Thanks for any help!

#365960

Minesh
Supporter

Languages: Anglais (English )

Timezone: Asia/Kolkata (GMT+05:30)

1)
Views offer you to put only search form on one page and search result on another page.

When you try to insert your view to the page, it will give you options to insert only search form and display results on another page. I think this will suit your requirement.

Please refer to the following link:
=> https://toolset.com/documentation/user-guides/front-page-filters/
[ Refer section: "Displaying the Parametric Search View on the Site" ]

Does this help?

2)
I need your problem URL so that I can see how you configured your filters and your views configurations.

Also, if possible, please send me a test case with your problem URL so I'll try to follow your test case and will try to build solution if possible after checking your test case.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#366115

Ok I think I might have worked a way around it, but now I need a way of ensuring that the default state of my filter checkboxes is "checked".

So when a user first loads the page all of the checkbox filters are checked. That way they can go and uncheck the ones that they need. Is there any way to do this?

#366276

Minesh
Supporter

Languages: Anglais (English )

Timezone: Asia/Kolkata (GMT+05:30)

To select all checkbox by default, we need to add custom javascript.

Could you please check now:
hidden link

I've added following code to your views JS box:

jQuery(document).ready(function($){
  $(".wpcf-form-item-checkbox :checkbox").prop("checked", true);
});
#366420

Thanks that does work for what I need. I basically just changed the filter to the operator NOT IN and then changed the checkbox styles with css to reverse the looks of checked and unchecked. Then with that js the checkboxes start off checked (which to the user is unchecked). It's a bit confusing but it works, so thanks for the help!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.