Skip Navigation

[Resolved] Searching field inside a Repeatable Field Group

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

Problem:
How can we create a View that has a Custom Search for the fields in a Repeatable Field Group we added to our posts?

Solution:
You need to create a View to query the actual "Post type" Repeatable Field Group.
Then you can add Queries to that View like for any other View querying post types, so you can add the actual search for the fields inside of the Repeatable Field Groups like you do it for other post fields in Views searches.

Note that this will display ALL the repeatable Field items, so if you want only fields of a specific post, you need to pass this in the Query of the View (get posts with a parent like...)

This support ticket is created 4 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 16 replies, has 2 voices.

Last updated by ericK-4 4 years, 11 months ago.

Assisted by: Beda.

Author
Posts
#1508727

Hello, I make a directory advocate website.
In toolset, i made a custom post type : “Avocat”
with some fields like : photo, first name, last name, email, website
and a repeatable group for the adresses because some advocate have got several offices with this field : address, zip code and town. I used Relevanssi for searching text inside this group.
To display all this information, no problem I made a “view” in a single and archive page. And a view to display the offices.
The problem appear when I want to add a search function. If I search a field that is not in the repeater group it is ok.
But my client want to search advocate by town. I made a search field with town and toolset says that there’s nothing. I spent several hours on your site between docs and forum and I found any information about that. I thought that with toolset it will be easy but not at the first glance. Thanks for you help !
Address of the website in dev : hidden link

#1510001

Toolset integrates with Relevannsi:
https://toolset.com/documentation/user-guides/views/searching-texts-custom-fields-views-relevanssi/

For Repeatable Field Groups, you will need to know that those groups are in fact posts, connected to the post where you add the fields, in a post-relationship.
So the "Avocat" post will have as many related Posts of the Repeatable Field Group Type, as you add "repetitions" of that group to the singel Avocat.
The fields themselves are then saved as postmeta to those related Repeatable Field Group posts, which in turn relate to the actual Avocat Post.

You can see more information on this detail here:
https://toolset.com/forums/topic/get-repeatable-field-group-for-relevanssi-search/
https://toolset.com/forums/topic/repeatable-group-field-in-relevanssi-search/
https://toolset.com/forums/topic/text-search-for-custom-fields-in-repeatable-group/#post-1300133

I think the issue you face is maybe due to trying to filter the Avocat Posts directly for the Repeating Field Group Fields - this is not possible.
You'd need to filter by those Fields, in a View that lists the Post Type corresponding to your Repeatable Field Group.

Please let me know if this helps?

#1511335
search-view.jpg

Hi Beda,
Thanks a lot for you advices.
To recap it is directory site where you can find advocate
There is a search function where people can find advocate by town. The advocate can have several adresses.
So in toolset a custom post type is created Avocat with some custom field and a repeatable group for the adresses.
Problem. How can i make a search by town and the result display the advocate information + town

I follow this thread :
https://toolset.com/forums/topic/text-search-for-custom-fields-in-repeatable-group/#post-1300133
and make a screenshot of my view search. I still not find the manner to make a search with the field “ville” because i don't understand the last step of Waqar thread and the conditionnal thing. Thanks to help me on this.

Address of the website in dev : hidden link
Best regards
Eric

#1514135

Hi Beda,
Have you seen my post ? Can you answer me please because I am still in a no way here
Thanks
Eric

#1514351

Yes, I've seen it - but I was on weekend the last 2 days, please refer to https://toolset.com/forums/users/beda-s/

As mentioned you can NOT make a custom search on the view that lists Advocates fort those Repeatable Field Group's Fields.
You need to create a new View, query the Repeatable Field Group Post type, and then in that View, you can add a search for the Custom Fields of that Repeatable Field Group.

Waqar talks about Relevannsi integration there, and it's meant to be used on a View that lists those posts (repeatable field groups) because it is not possible to query by fields of related posts in a single View.
If you need this, I'd suggest adding your case and voice here https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/ so the Product Management can plan this for future development cycles

You can have such search only on a View that lists those Repeatable Fields directly.

#1514425

Hi Beda,
Excuse me first not to see that you are on weekend !
Can you tell me more more about the “query repeatable field“ because I think that it is what I done when you look et my screenshot
A bit confused here
Thanks a lot for your support
Eric

#1514513

That's right, the Screenshot shows the View querying a Repeatable field Group with 2 Searches.

And when I search that view I see hidden link, all related to Paris.

This seems to work. Maybe you can add login details and the precise URL to the issue with steps, in case this is not what you expect to be output.

I am not sure how many of those Repeatable Field Groups have Paris saved, but if there are many, that is what the View will return.
If you want to restrict it, you need to specify the Relationship to look for, in the Query Filer of that View so only Repeatable Field Groups of (for example) the current post are shown.
Then that View would need to be put in a single "parent" post (the Advocat).

#1514609

On the Home page, there are 2 views
hidden link and hidden link

Both queries the same "Bloc adresses" Repeatable Field Group.
Why is this so? Usually, you will want only one View on the page.

In any case, the View hidden link has no Search and will return all Repeatable Field Groups of the Post where the view is inserted.
Additionally, it will get ANY related post, of that type, no matter in what relationships.

It will not create any searchable content so I think you can remove it.

The other View hidden link has only a filter by fields, and as I stated earlier, your view that queries that Repeatable Field Group must define which ones to display, or it will display them ALL.
So, in this case, it will display ALL Repeatable Field Groups of ALL posts.
And when searched, it will show all those matches, which is precisely what happens on the homepage when looking for "paris" (example) in the search.
At least, that was what happened 2 hours ago here hidden link
Now, it returns no results.

I assume you have changed something meanwhile, which if reverted will fix the issue.
Maybe you inserted the second View meanwhile, which now disturbs the results?
Or those Fields have no "Champ Nom" filled out, and hence, won't appear in the View (that is the Orderby Setting if the value is not set, it will not show the post in the results)

Can you let me know what was that changed to the previous setup?
It will most likely be the required action to fix the issue

I also see no Avocat Post Type on the site, which is it that has the Repeating Field Group assigned?

#1514677

Hi Beda,
Yes, the thing you think that is the result of the town is another field who gives the town of the Court of law and this field is not in the repeater group.
To make the thing easier. I simplify the searchable view -> ville search and there s only one field for searching.

So I want to search the town (ville) where the advocate works what it is present in the top of the “view“ panel
At the bottom the result :
the name, the surname and the email -> not in the repeatable group but in custom post type -> Adhérents
And the field town (ville) -> in the repeatable group “Bloc adresses“ who is present in custom post type -> Adhérents
So that I want simply is that when I type a name of a town in the search field ; toolset returns all the advocate working in this town and give me the result like so :
Name - Surmane - Email and the town
Hoping that you understand me with my poor english 🙁
Thanks a lot really
Eric

#1515983

I've set up an example for you, I think it's easier, to explain the limitation.

I used your specifications as here:

So that I want simply is that when I type a name of a town in the search field ; toolset returns all the advocate working in this town and give me the result like so :
Name - Surmane - Email and the town

I've built a View here:
hidden link

It queries the RFG (Repeatable Field Group) and has one search for its "Ville" Field in that RFG.
In the Loop of the view, we show the name of the RFG, the Ville and the post that RFG belongs to.

I have inserted it here hidden link
It looks broken in the front end (style), I am not sure why, and the view isn't even visible.

I can't assist with design issues, for this problem, so we will need a page where I can insert the View as clean as possible so to show you what is possible with it and what not.
For example, the View will show ALL RFG addresses, but when you then filer for Ville, it will show ONLY those that have Ville == your search value.
And since we display the "parent" Avocat post title in the results, you will have data of the post the RFG it belongs to (the avocat)
This basically means you can find all Avocats in Ville == Paris, or similar.

But right now some design issue seems to block the front end output of the test page.

#1516033
Capture d’écran 2020-02-19 à 10.03.16.png

Hi Beda
I put in place your view “View for RFG” on the homepage and it works but can you explain why toolset returns the value for line 3 to 6 ?
3 Pau Pau
4 Pau Pau
5 Coordonnées Adhérents Pau
6 Coordonnées Adhérents Pau
I appreciate a lot the quality of toolset support
Best regards
Eric

#1516057

Because you search by pau, the value there is pau, so... it finds it.

I've amended the Loop a bit to clarify why it finds what.

#1516261
Capture d’écran 2020-02-19 à 13.47.35.jpg

Hi Breda,
Near the end ! I put the fields I want in a view I made inspiring by yours a new view “View for RFG-final” without css layout for the moment.
Just 1 thing, I still not understand why toolset send so many “ville” field without other information in it like photo name... I verify in adherent custom post type and to see if there's some empty post but not.
Select a town and you will see what I mean or look at the the screenshot. Hoping that you understand what I mean
Thanks a lot
Eric

#1517925

I see the issue, there clearly seem to be orphan RFG items.

See the debug output I added (it's currently in HTML comments, remove them to see the output)
It shows, that RFG Items for Marignane were added 4 times:
Post-ID 3624, 3126, 2661, 2197
Only one of them (3624) is properly saved and linked to the actual Avocat (Yepremian-Ohayon Eve)

So that means something was problematic when adding the RFG, it added 4 times, not once.

We need to check in the database and probably delete those posts manually, but lets first find out why this happens.
It is not usual with Toolset, so it could be custom code or another plugin provoking this.

Can you try to create a new Example Post and check how many RFG is added if you add ONE RFG item only?
Later I will need MySQL access (PHP myAdmin is OK) to see the database.
I can also look at this locally, in that case, I'll need a copy as per https://toolset.com/faq/provide-supporters-copy-site/
I've enabled a private reply, in case that's required.

Right now you can work around the issue by limiting the view output to one. But that's not a solution for always

#1517959

Hi Beda,
Ok, I see where the problem come from. I made several test in importing the data with a CSV file and delete each import but I don't think that they still be present in the database. So, it is for the moment a dev site. I will make a new custom post type and make some tests today. I will inform you
Thanks a lot
Eric