Tell us what you are trying to do?
I am using parametric search. I have a drop down selector, which is populated by all possible values for that field ("specialty1"). This is working great.
But I actually have two fields that I need to search, "Specialty 1" and "specialty2". I cannot have separate drop down boxes, so I want to combine the two fields into one field. Example:
Record A: surgeon
Record B: dentist
Record C: physician
Record D: physician, surgeon
using the above example, I want the drop down list in the parametric search to populate for 3 possibilities ( surgeon, dentist, physician ) and two return two results for "surgeon" (Record A and Record D)
Is this possible?
(I am using Classic Editor and views, but could change to blocks if absolutely necessary)
Is there any documentation that you are following?
Is there a similar example that we can see?
What is the link to your site?
Hello and thank you for contacting the Toolset support.
Combining two custom fields in one filter is not possible out of the box. But, it can be implemented using custom code. For example, you can create a custom field using shortcodes and HTML, and then you can hook, using PHP, into the view's query and modify the arguments to use both fields:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
Or you can use two filters, and implement a custom Javascript code, that will hide them, build one filter, and sync the filter selection for both fields, then trigger the search.
However, I am not really sure to understand the use case. If you provide more details, it may be a different solution. Can you answer the following questions:
- What are the possible values for "Speciality1" and "Speciality2"?
- Can you provide some background about them? Why have you used 2 fields instead of 1?
- How many posts do you have currently for this custom post type? If you have just a few, we can implement a different data model, update the posts manually and get a more elegant solution.
Thanks for the response.
Let me try and clarify. I have two fields, Specialty1 and Specialty2. These describe a doctor's specialty. Some doctors have 1 (specialty1) and some doctors have 2specialties (specialty1 and Specialty2). Right now, my parametric search allows for search for "specialty1". But this excludes doctors who might have the specialty listed under "Specialty2". I DON'T want to have two separate input boxes in the search bar (for specialty1 and specialty2).
My work-around this is to combine all specialties into 1 field (Specialty1), delimited by a comma. I assume I can then search by using the IN function. (I don't have a problem with how to combine them.)
My problem: I want to also populate my drop down box in the search box with all the UNIQUE specialties available in this new setup.
For example, for these records...
Record A: surgeon
Record B: dentist
Record C: physician
Record D: radiologist, oncologist
...the drop down box should include options [surgeon, dentist, physician, radiologist, oncologist] as FIVE separate options. Then if someone searches for Oncologist they get Record D as a result. Can this be done?
Hope that makes things clearer!
Thank you, that's even more clear. However, with this current data model(two custom fields), it won't be possible without custom coding.
Depending on several factors, the custom code may be complex to build and may also have edge cases. For example:
- Are the specialties fixed, or they may be added by the users(using a Toolset form)?
- What is the type of these fields? Select/Radio/Checkboxes fields will be much easier to handle than Single line fields.
- The view will use AJAX or not.
- Would you like to handle cases where the users do not have AJAX?
On the other hand, using a different data model, we won't need any custom code at all. For example:
- Using one single line field "Specialty" that accepts multiple values.
- Using a "Checkboxes" field.
- Using a Select or Radio field that accepts multiple values.
- Using a custom taxonomy.
That's why I asked how many posts do you have currently, so we can consider changing the database model and updating the posts manually.
I hope this makes sense to you. Let me know your feedback or questions and I can give a detailed example, suggestion or advice.
Hi,
The solution is simple, now that you mention it ! 🙂
1. I can definitely update current posts manually to a new data structure.
2. Any of the options you have suggested would work for me, as the specialties are "pre-set". Probably using a checkbox field is the best solution.
Am I correct to understand that if I use a checkbox field the parametric search drop-down box will populate with all relevant values?
Many Thanks!
Am I correct to understand that if I use a checkbox field the parametric search drop-down box will populate with all relevant values?
Exactly, taking the example from your earlier post:
Record A: surgeon
Record B: dentist
Record C: physician
Record D: physician, surgeon
Choosing "surgeon", in the filter, will return Record A, and Record D.
Choosing "physician", in the filter, will return Record C, and Record D.
The field filter can be used as a dropdown or as checkboxes. Either on the blocks editor or on the legacy views editor.
If you choose the field filter as checkboxes, filtering with "surgeon" and "physician", will return Record A, Record C, and Record D.
Let me know if you need any further assistance.