Skip Navigation

[Resolved] Repeatable Group Field in relevanssi search

This support ticket is created 5 years, 1 month 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.

Our next available supporter will start replying to tickets in about 3.70 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 8 replies, has 2 voices.

Last updated by Nigel 4 years, 10 months ago.

Assisted by: Nigel.

Author
Posts
#1355669
Search-Index.PNG

I am trying to:

To add my Repeating Field Group field to search I need to index my RFG and add the RFG custom field to Relevannsi settings:
- Index RFG from (Settings > Relevannsi > Indexing tab > Post Types > your_rfg_slug) ---> successfully done !
- Index RFG textual field from (Settings > Relevannsi > Indexing tab > Custom Fields > Some, insert your wpcf-PREFIXED_textual_rfg_field_slug) ---> I am stuck here !
- Save and Build index

Problem: I don't understand how I create the "wpcf-PREFIXED_textual_rfg_field_slug" !
I attached an image, where one of the fields, that should be indexed can be seen. How should the "wpcf-PREFIXED_textual_rfg_field_slug" should look like for this field?

Many thanks in advance.

KInd regards
Lara

#1355711

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Lara

Types stores custom fields with a 'wpcf-' prefix, so if your field slug is name-reitlehrer then the actual post meta key would be wpcf-name-reitlehrer.

That's the key any direct calls to the database or other plugins would need to use.

#1355739
Search-Index2.PNG

Many thanks, Nigel.

It works fine with every field, besides with the fields in the repeatable group. I did all steps like discribed above, but it still doesn't work. I use a view to display the fields in the repeatable group. What do I need to change to make it work?

Kind regards
Lara

#1355769

Sorry, I meant: I use a view to display the fields (from the repeatable group) in the custom search.

#1355773

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

There may be a deeper problem here, inasmuch as there are limitations in how repeatable field groups can be used in Views custom searches.

Firstly, searching posts by fields that belong to repeatable field groups is not currently supported.

For example, if you have a "Company" post type, and this has a repeatable field group "Offices" with fields for phone number, email address, location, staff count etc., then you cannot create a View to search Companies and include filters for location or other fields belonging to the repeatable field group.

If that is what you are aiming to do, it has not yet been implemented, and I recommend you submit a feature request (at https://toolset.com/home/contact-us/suggest-a-new-feature-for-toolset/) so that the product manager is aware of the demand when it comes to prioritising development.

What you can do is to make a Views custom search specifically of the repeatable field groups, so in my example you could create a search for Offices and include filters for the fields comprising the repeatable field group, as well as including a filter for the Company they belong to.

Except! We have a known issue whereby this doesn't actually work properly currently: https://toolset.com/errata/views-has-issues-when-creating-repeatable-fields-groups-fields-filters-and-when-displaying-the-view/

The developer has proposed fixes for the above and the changes just need to complete testing before a plugin update can be released. Hopefully that will be next week, but in the meantime you are unlikely to be able to add searches for repeatable field groups, even though you have been able to set up the indexing with Relevanssi.

I can let you know when the update is available.

#1355783

Hi Nigel,

many thanks for your answer. Can you please explain this point: "What you can do is to make a Views custom search specifically of the repeatable field groups, so in my example you could create a search for Offices and include filters for the fields comprising the repeatable field group, as well as including a filter for the Company they belong to." a little bit more in details. I think unfortunatelly I don't get it.

Waiting up to a week or a little longer isn't a problem.

Kind regards
Lara

#1355817

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Unfortunately I can't demonstrate it to you with screenshots, because at the moment it's not possible to create such a search.

But it may help you to understand how repeatable field groups are implemented.

Again using the example of a custom post type "Company" with a repeatable field group "Offices".

When you add normal custom fields to a post type they belong to that post type (the posts are saved in wp_posts and the corresponding custom fields are stored in wp_postmeta together with the ID of the post they belong to).

When you create a repeatable field group behind the scenes Types creates a hidden custom post type for that repeatable field group, e.g. a post type "Offices".

When you edit a Company post and add a group of fields, a new Office post is created, and the group of fields belong to that Office post (not to the Company post). Add more Office groups, and each set of fields belongs to the corresponding Office post.

Types knows that these Office posts relate to the Company post being edited because it creates a relationship, with Company as the parent and Offices as child posts.

So, returning to creating a custom search, the underlying WordPress code for querying posts is the WP_Query class, and with that you can only filter posts by properties of the posts themselves. So if you have fields (not part of a repeatable field group) that belong to Companies, then you could search Companies by those fields. But the repeatable field group fields don't belong to Companies—they belong to the hidden Office posts—and so you cannot filter Companies by the repeatable field group fields.

You can create a View to query Office posts (the container post type for the repeatable field group) and filter by its fields.

That could return Office posts belonging to any Company, which may not be what you want, but you can also add a relationship filter to the search, to specify which Company the Office posts (the groups of repeatable fields) should belong to.

In the output section of the View you can output fields not just from the groups of repeatable fields, but also from the parent, i.e. the original post to which the groups of repeatable fields belong.

It would be easier to show you with an example, but because of the current issue it's not working, so let me tell you when the update is available, and then I can give you a demonstration if needed.

#1356043

Hi Nigel,

many thanks for your explanaition.
This sounds awesome.

It would be very kind, if you could give me a demonstration,
as soon as the update is available. I would love to see it.
I will wait with patience.

Kind regards
Lara

#1446865

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Lara

There were some plugin updates today and I just noticed that I hadn't replied to this, even though the original problem with creating custom searches for repeatable field groups was fixed some time ago, sorry about that.

So if you update to the current version of Views, you should find that you can now create a View to search RFGs.

I can guide you through it, if you like, but it would probably help if you gave me a specific example of what you want to implement (in English) in terms of the structure of the parent post type, what the repeatable field group is/what it's fields are, and how you want the search to work, i.e. whether you want the users to specify the parent post and only search within repeatable field groups belonging to that parent, or to search fields of the repeatable field group irrespective of which parent post they belong to (but to display which is the parent when outputting the results).