Skip Navigation

[Resolved] Relevanssi debug not finding content in RFG

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

Problem:

I am having trouble getting content within Repeatable Field Groups (RFG) to show up in Relevanssi search results. I have followed the steps to include custom fields in the indexing, but specific words within the RFG aren't showing up in the search results.

Solution:

Ensure that the child post type for the RFG is included in the Relevanssi indexing settings. In the Relevanssi indexing tab, ensure the post type is indexed and check the "Respect exclude_from_search" option under the Searching tab. Use the ID of the child post when debugging.

Relevant Documentation:

https://toolset.com/forums/topic/front-end-search-for-repeating-group-field/

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.

This topic contains 13 replies, has 3 voices.

Last updated by Christopher Amirian 2 months, 1 week ago.

Assisted by: Christopher Amirian.

Author
Posts
#2734221

I'm having issues getting content within RFG to show up in Relevanssi. I've taken all of the necessary steps to check on the Post Types and included all of the related custom fields in the Indexing tab of Relevanssi. When I debug a page id within Relevanssi's debug tab, I can see that a specific word that is in a RFG isn't showing up. How can I troubleshoot and fix this?

#2734787

Nigel
Supporter

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

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

Hi there

If you are having problems relating to data in repeatable groups of fields it likely relates to understanding how they are implemented.

To illustrate, let's use an example with an Offices repeatable group of fields, that has individual fields for Phone, Email, Manager, and City.

Custom fields are stored in wp_postmeta and belong to a specific post.

We add several Offices groups to our Acme, Inc post, filling in details for each of the fields.

So, in wp_postmeta, attached to the Acme, Inc post we have several phone numbers, several email addresses, managers, and cities. But nothing to connect a particular phone number to the associated email address, manager, and city, they are mixed up. (We'd essentially need an extra column in the table to group the field entries.)

The Toolset solution is to store each group of fields against a child post of the Acme, Inc post. As many child posts are added as groups of fields are added, one for each Office in our example. That means the fields like phone and email address belong to the child office post, not to the original Acme, Inc post.

That's why you would use a View to output the repeatable groups of fields belonging to the Acme, Inc post, for example, where the View actually queries the child post type.

With respect to Relevanssi indexing the data, the debug info won't show the indexed fields if you put in the ID of the main page (e.g. the Acme, Inc post), you would need to put in the ID of the child post for that group of fields (the particular Office, in our example).

In the Relevanssi indexing settings, under post types you need to make sure the child post type (which has a slug based on the name of your repeatable group of fields) is included in indexing. You will see that the post type is nevertheless "Excluded from search", and Relevanssi will indicate that you need to go to the Searching tab and disable the option "Respect exclude_from_search".

If you rebuild your index, the field content should then be included in index.

#2735868

Nigel,

Thanks for the reply.

I have Relevanssi setup correctly and am using the Search & Filter plugin to conduct filtering on search results.

To fully test this, I have disabled that setup and am using the default WP search function. Keep in mind, I'm not using a View but rather a PHP template. When I search for content within a RFG, I now see a result but it's a result for the RFG as you detailed above. The issue is the link (/items/rfg-199/) isn't a valid link. How would I go about ensuring the parent post is what shows up in the results?

#2737141

Christopher Amirian
Supporter

Languages: English (English )

Hi,

I'm not sure if I understand what you mean by The issue is the link (/items/rfg-199/) isn't a valid link.

Would you please give more detailed information on what you do and what you expect so that I can help here?

If you decide to use the views you can check this link for more information:

https://toolset.com/forums/topic/front-end-search-for-repeating-group-field/

Thanks.

#2738565

Christopher,

What I would expect to happen is when I search for a keyword, the result would be the parent page/link. Right now the search result is the actual RFG child with a link to a page that doesn't exisit. I can send some links privately if that is helpful as it would likely explain things better.

#2740886

Christopher,

What info can I give you to help move this along?

#2741499

Christopher Amirian
Supporter

Languages: English (English )

Hi,

Sorry for the late reply.

Yes it will be helpful that you share a link and maybe explain the problem by creating a video, you can use loom.com

So I can see where you go and what you do ion the search and what you expect.

You can set the next reply as private to provide the links you have mentioned.

Thanks.

#2742929

Christopher,

If you goto hidden link (pw: lisi), you will see two links. The top one links to hidden link, which isn't a page. Instead, I'd expect it to find "Elsmere" on this page hidden link as it's part of a RFG for this page.

#2743564

Christopher Amirian
Supporter

Languages: English (English )

Hi,

I asked the second-tier support to check the issue.

Meanwhile, I'd appreciate it if you could give me the URL/User/Pass of your WordPress dashboard after you make sure that you have a backup of your website.
It is absolutely important that you give us a guarantee that you have a backup so if something happens you will have a point of restore.

Make sure you set the next reply as private.

#2744264

Nigel
Supporter

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

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

Hi Keith

Let me step in here.

As your are working directly in the PHP templates you'll need to do a little more work than if you were simply creating templates within Toolset.

As I explained above, the fields belonging to repeatable groups of fields are stored in posts of a special post type for that RFG which are child posts of the post the groups of fields were added to. When I say child posts, I mean via a Toolset relationship.

If the search returns some posts that are looped over to output the results, in the case of a result that was found within a repeatable group of fields that means that the current loop item is one of these child posts. You want to output the title and link to the url of the parent post, not the child post.

That is straightforward when creating Toolset templates, because when you add some field to a template (e.g. a link to a post) you can specify that the source of the field should not be the current post but the parent post instead.

If you are working directly in the PHP templates you'll need to replicate this yourself.

You could use the Relationships API to get the ID of the parent post (knowing the ID of the current post which is a child post).

But it might be easier to generate the same shortcode that would be used in a Toolset template (that includes the attribute that point to using the parent as the source), and add that to your PHP template with do_shortcode().

Here is an example from my test site, a shortcode to output the post title as a link to the post, where the context is a child post that contains a group of fields, and where I specify that the title and link should be from the parent post:

[wpv-post-link item="@items.parent"]

On my site my repeatable field group is called "Items" and has a slug of "items".

#2744474

Nigel,

Thanks for the reply. A few questions:

1. How would we handle this if we have multiple RFGs used throughout different sections of the site? Your example calls the "Items" RFG but we would need to account for several others as well.

2. To complicate things further, the example I gave you previously is actually a RFG (items) of a RFG (content-rows) of a CPT (service). So, when I use the shortcode above, it's outputting the parent RFG (Case Study) rather then the actual page.

#2745600

Nigel
Supporter

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

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

For 1, as you will be iterating over the search result posts, some of which will be of types pertaining to your RFGs, you'll need to get the post_type for the current loop item: that will give you the slug of the RFG that you can then apply dynamically as the value of the items attributes of shortcodes such as wpv-post-link as described above.

For 2, if you have nested RFGs inside each other, then you can't use the shortcode to refer to what is essentially a grandparent post rather than a parent.

You would need to use the Relationships API and the toolset_get_related_post function. (Because you are retrieving a parent, of which there can be only one, you can use the simpler toolset_get_related_post function rather than the more complex toolset_get_related_posts function where multiple results are possible, e.g. when retrieving child posts.)

Knowing the ID (e.g. '123') of the current post and the slug of the RFG posts (e.g. 'subsets'), that slug is also the slug of the relationship, needed as an argument in the function.

So to get the parent post you would make a call something like this:

$parent_id = toolset_get_related_post( 123, 'subsets', 'parent' );

With the possibility of nesting RFGs, where you might need to get the parent of the parent, you can effectively do this recursively until it returns 0 (there is no parent), meaning you have gone far enough.

#2747271

Nigel,

For #1, I'm having trouble wrapping my head around what the code will look like to accomplish that. I just went through all the Custom Fields for this site and we have 31 instances of RFGs used. Would I need to create an if/else statement that includes all 31 instances to ensure I am getting the right post_type? How would I then grab the slug of the RFG?

#2747885

Christopher Amirian
Supporter

Languages: English (English )

Hi,

RFG slugs should be unique so if the user has 31 RFG (not the items belonging to RFG) - then yes you will have to use 31 RFG slugs to get the related parent.

But if he has only one RFG and 31 items belong to that RFG then the code line my colleague shared to get related parent is enough.

Please consider that this is getting in a custom development territory which is outside of our support scope. If needed you can use this link to hire a contractor to handle the scenario.

Thank you.