Home › Toolset Professional Support › [Resolved] Search Bar related to Nested Views
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 |
---|---|---|---|---|---|---|
- | 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)
This topic contains 9 replies, has 3 voices.
Last updated by simchaH 2 years, 9 months ago.
Assisted by: Minesh.
Hello,
I know that as of now Toolset does not support searching through nested views in a loop. I am wondering if there is any workaround that may have been given to other Toolset users in the interim?
I currently have my main parent view as a location, and that is tied to my map and location search. Then I have a nested view with information about the location, and I want two filters based on that nested view. - If I swapped views and made the nested view the parent, will that help anything? Or is there a way to nest two searches, like nesting two views?
Thanks,
Sim
Hello. Thank you for contacting the Toolset support.
The thing is that, if you create a custom search view for your child post type (that can include frontend filter for fields belongs to child post type) then we can have access to the parent (if its one to many post relationship).
Can you please clarify for what fields you want to add as frontend filters and those fields belongs to what post type as well as what post relationship you created between your post type.
So the two filters I would like to add are both from either Post Titles, or both from single line custom fields as they are the same thing by me because - in my Post Type, I have it duplicated where a persons full name is the Post Title, and I split up the first and last name as two custom fields, so either one of these work.
This person Post Type is a child related to the Location noted above. As a step #1, is there a simple way to get such a frontend filter working, where any person connected to a location can show up in the loop?
The more complex step #2 is that I would like to differentiate between these two filters based on whether a multi-checkbox field is checked. (This checkboxes is part of the persons custom group fields) -Meaning, for Filter A, if option "0" is checked, then I want those people's names to be filterable (meaning, all Locations that person is related to, should display in the loop). And for Filter B, if option "1" is checked, then I want the other persons names to be filterable. - If there is a simple solution for this by changing the multi-checkbox into another custom field type, or a taxonomy, I would consider that.
Thank you!
Sim
Hi Sim,
Minesh is currently on Holidays today but will be back tomorrow to continue with you on this thread.
Thanks,
Shane
You can build a text search to search within the post title:
If you are using classic views:
- https://toolset.com/documentation/user-guides/views/filtering-views-for-a-specific-text-string-search/
If you are using blocks ( you can also setup text search and search within single or multiline custom fields)
- https://toolset.com/course-lesson/searching-texts-in-custom-fields-with-toolset-and-relevanssi/
Here is the Doc you should follow how to setup custom search:
- https://toolset.com/course-lesson/creating-a-custom-search/
The more complex step #2 is that I would like to differentiate between these two filters based on whether a multi-checkbox field is checked. (This checkboxes is part of the persons custom group fields) -Meaning, for Filter A, if option "0" is checked, then I want those people's names to be filterable (meaning, all Locations that person is related to, should display in the loop). And for Filter B, if option "1" is checked, then I want the other persons names to be filterable. - If there is a simple solution for this by changing the multi-checkbox into another custom field type, or a taxonomy, I would consider that.
==>
I'm not sure what exactly you want to add it as filter here for filter A and filter B, if you can share test case example and also share how exactly you want to display the results then I will be able to guide you in the right direction.
- Do you want to display the results group by location? For example:
Location 1: - Post 1 - post 2 Location 2: - post 3 -post 4
You can also try to setup a test site on our free test platform http://www.discover-wp.com and create a test site using any of our reference sites and try to play with it and check what filters you want to add is possible:
-https://discover-wp.com/site-templates/
"You can build a text search to search within the post title: "
You mean to say that I can create a text search for even text that is contained inside the nested/child view? That would be perfect!
I am using classic view for the view itself, and I'm using blocks editor for the content template loop inside of the view.
- Do you want to display the results group by location? For example:
Location 1:
- Post 1
- post 2
Location 2:
- post 3
-post 4
Yes you are correct that is exactly how I have it set up! Right now I can only utilize searching inside the "Location 1" or "Location 2" posts, because those are the main/parent posts of the view.
I am trying to add the ability to search by the Post Title of Post 1, Post 2, Post 3 etc. inside of those Location Posts, with the results of the search displaying them (and their parent post obviously). However, the one main part that adds to the "technicality" of the filter, is that I can't simply bring in every single Post Title to this "nested" filter, because there are hundred of child posts (i.e. post 5, post 6) that are not attached to any Locations, and are not necessary to display, and that will show up in the filter. Therefore I need the multi-checkbox to serve as a conditional statement, saying that if a certain option in the multi-checkbox in the child Post 1 or Post 2 etc. is checked, then the Post Title should be displayed in the Filter. If it is unchecked, then I don't want it there, because it will just confuse users.
The reason I brought in Filter A and Filter B, is because this exact example above I need duplicated. There are two options in the multi-checkbox for child posts that I would like to display in this filter. One Filter (Filter A, for example) will only display Post Titles for Post 1 & Post 3, because only "option 0" in the checkbox is checked. The other Filter, Filter B, will display Post Titles for Post 2 & Post 4, because only "option 1" in the checkbox is checked. So these will be 2 separate filters right next to each other, one that has "Label 1" which searches through all "option 0" of the child posts, and one with "Label 2" which searches through all "option 1" of the same child posts, and they both return the filtered Post Titles of that related Child Post.
I hope I explained clearly!
Thanks,
Sim
You mean to say that I can create a text search for even text that is contained inside the nested/child view? That would be perfect!
==>
No, you can not add search text filter to nested view as it will add search text box for every child iteration. That is not the solution.
Please note that you can build custom search for the post type for which you set your view to query. If you set your view to query post type A, then you can add frontend filer (search text box or any fields belongs to post type A) for only post type A. If you set your view to query post type B, then you can only add frontend filters using fields belongs to post type B.
Now, the issue in your case is you also want to group by the Location. Lets say we set the view to query child posts "person", you can add the search text box and we can add some filter so that it will search for posts for both child (person) and parent (Location) and search for post Title within both post types but then we can not group by location but we will able to display location with every post.
So, what approach you would like to go with?
Lets first go step by step and then think for more complex functionality.
"Please note that you can build custom search for the post type for which you set your view to query."
So can I set my search to query all posts? So that I can search through everything?
"...but then we can not group by location but we will able to display location with every post."
How will the location be displayed? To me, it makes the most sense to have the Location as the main view, because each Location can have many children posts inside, but each Location is only once. So if I understand correctly, if we change it around then the same Location can show up a bunch of times, since for each child post it will be displaying.
If I am correct in what I'm saying then this may not be the best approach as it might get confusing to the end user. Are there any other ideas you may have?
I've created this test site for you, you can login to the site using the following link:
- hidden link
There is One to Many post relationship setup between post type "Personal Trainers"(One - Parent) and "Sessions" (Many - Child):
=> hidden link
I'v setup the following custom search view "personal-trainer-search" which is setup to search within the post title of post type "Personal Trainers":
=> hidden link
I've also setup the following view which will display the related child that is set to query the post type "Sessions":
=> hidden link
I've added the above child view within the "personal-trainer-search" template's output so that when you search for personal traininer it will search for keyword you input and search within post title and content and then display the result and it will also display the associated sessions to personal trainer:
=> hidden link
<li> [wpv-post-link]</li> [wpv-view name="session-belongs-personal-trainer"]
I've create the following page that will display that nested views:
=> hidden link
This way you can display the child posts group by parent post.
My issue is resolved now. Thank you!