Skip Navigation

[Resolved] Searching keywords from repeating field group is not working

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

Problem: I would like to be able to use text search to find posts using information stored in repeatable field groups. However, when I add RFGs to the index I see links in the search results that point to an invalid post. I would like to link to the post containing the RFG.

Solution: Add the repeatable field group to the search index, then use a WordPress Archive to display the search results. Use conditional HTML in the archive to determine if the link is for a RFG post type, and display a link to the parent post instead. Something like this:

[wpv-conditional if="( '[wpv-post-type]' eq 'custom-page-section' )"]
[wpv-post-link item="@custom-page-section.parent"]
[/wpv-conditional]
[wpv-conditional if="( '[wpv-post-type]' eq 'custom-post-section' )"]
[wpv-post-link item="@custom-post-section.parent"]
[/wpv-conditional]
[wpv-conditional if="( '[wpv-post-type]' ne 'custom-page-section' ) AND ( '[wpv-post-type]' ne 'custom-post-section' )"]
[wpv-post-link]
[/wpv-conditional]

Relevant Documentation:
https://toolset.com/documentation/user-guides/searching-texts-custom-fields-views-relevanssi/
https://toolset.com/documentation/getting-started-with-toolset/customize-post-archives/

This support ticket is created 6 years 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 28 replies, has 3 voices.

Last updated by eddieW-2 5 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#1147295

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Screenshot 2018-11-15 at 10.32.33 AM.png

Hi Eddie,

Thank you for the info.

I've found the issue.

It seems that you were including the RFG in your indexing.

Take a look at the screenshot and ensure both items are unchecked and then rebuild the index.

Thanks,
Shane

#1148747
Screenshot_1.png

Hi Shane,

I had unchecked both of the items and i get another issue where when i type "Murale" it should show the result on homepage instead of no results, so is there any way do set the both item not to be excluded from search based on the attachment? Thank you.

#1149361

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Eddie,

Unfortunately not, it's because of how the RFG work. Where they are created as Hidden posts so if searched for, the hidden post will show up, rather than the actual post that it is attached to.

Thanks,
Shane

#1150626

Hi Shane,

If that's the case, may I know why when I search the following keywords, no search results appears?

1. Murale - Should show HOME PAGE but shows NO RESULT
2. Marblevo - Should show HOME PAGE but shows NO RESULT

But when I search for Bathroom Experience, it output the correct result for me which appears on this link: hidden link

Both the content of these pages is using the same custom field. The only difference is the fields are used in a page and another is in a CPT created with toolset.

#1150797

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Eddie,

It should be showing up now.

The problem was that relevanssi was not indexing the Products in woocommerce.

Thanks,
Shane

#1151810

Hi Shane,

It seems like the keyword "Murale" is only working because there is a product named Murale. Therefore, when the keyword is search, the result is leading to the product page. It is still not showing the result for the home page.

Following keywords from home page still yields no results:

  • Marblevo
  • Lux 2.0
  • Cementous

Thank you for your hard work, Shane 🙂

#1152641

Hi, Shane is on holiday so I'm following up on his open tickets. I can see that you have a Repeatable Field Group (RFG) assigned to Pages, and you're expecting the contents of this RFG to be searchable. In order to do this, the RFG must be indexed and must show up in search results. Otherwise, the contents of the RFG will not be exposed to the Relevanssi index, and are therefore not searchable. So this creates a problem where the RFG links in search results point to the wrong URLs. There are two options to fix this:
1. Use Toolset Views to create a WordPress Archive and assign it to search results. Use conditional HTML in the loop to show a link to the parent page or parent post if the current post in the loop is has an RFG post type. I can help with this if you'd like assistance.
2. Use custom code to create your own PHP template for archives or filter the existing theme template. This falls mostly outside the scope of support we provide here.

Let me know how you would like to proceed.

#1154426

Hi Christian,

I have chosen to use Toolset Views plugin. I already installed the plugin and created a WordPress Archive for search results, can you guide me on the next step as I have never used this plugin before?

#1154743

Sure, I can help. Edit this WordPress Archive and scroll to the top right corner of the screen. Click "Screen Options" and activate "Search and Pagination". Then scroll down to the Loop Editor section and click "Loop Wizard". Choose "Unformatted" for now and in the second popup screen add the post link and post type fields. Some code will be automatically generated for you. Scroll down to the "Loop item in Search results" area. You can add line breaks after each shortcode using br tags:

[wpv-post-link]<br />
[wpv-post-type]<br />

Test that out by performing a search on the front-end to see if it's working as expected, then I can show you how to add conditionals for displaying the RFG parent post title.

#1155894

Hi Christian,

I have done all the steps as stated above.

Just to check with you, by doing the steps, I still won't be able to see results for my RFG fields until I do the conditional fields? The search results work as usual, just without the keywords from my RFG fields.

#1157198

Just to check with you, by doing the steps, I still won't be able to see results for my RFG fields until I do the conditional fields?
I assumed you had already re-added the RFG fields to the Relevanssi index so they can be searched. If not, please set the fields to be indexed in Relevanssi settings, then rebuild the index. Then you can create the WordPress Archive as described above. At that point, you should be able to see search results from the RFG fields as before, pointing to incorrect URLs like DOMAIN.COM/custom-post-section/rfg-6/.

Next we will add conditional shortcodes to display the RFG's parent post link instead of an incorrect link for each of the RFG search results.

#1159107
Screenshot_2.png
Screenshot_1.png

Hi Christian,

I able to see the result, just like u mention the URL is wrong, so can u please guide me on what is the next step?

#1159751

It's recommended to test post type slugs, not post type names, so we will use the slug in a conditional. In the "Loop item in Search results" template editor, drop down a line and click "conditional output" above the editor to start a conditional block. In the data type field, select "Views Shortcodes" and choose the wpv-post-type shortcode. You want to test if the current post type slug is equal to "custom-page-section", which is the slug of one of the repeating field groups. Try setting that up with the conditional builder. It should generate a shortcode like this:

[wpv-conditional if="( '[wpv-post-type]' eq 'custom-page-section' )"]

Then just after that, use the Fields and Views button to insert a wpv-post-link shortcode. The default settings are fine for now. After you insert the wpv-post-link shortcode, add the "item" attribute to display a link to the parent post:

[wpv-post-link item="@custom-page-section.parent"]

The item syntax is "@", then the RFG slug, then ".parent", which will point to the post containing the RFG. After that, close the conditional output block by clicking "conditional output" again. Putting it together, you end up with a conditional that looks like this:

[wpv-conditional if="( '[wpv-post-type]' eq 'custom-page-section' )"]
[wpv-post-link item="@custom-page-section.parent"]
[/wpv-conditional]

Since you want to do the same for the custom post section RFG, you can copy + paste the code and adjust the slugs:

[wpv-conditional if="( '[wpv-post-type]' eq 'custom-post-section' )"]
[wpv-post-link item="@custom-post-section.parent"]
[/wpv-conditional]

Finally, you want to display the regular post link for all the other post types. So a third conditional is required that tests if the post type slug is neither custom-page-section nor custom-post-section:

[wpv-conditional if="( '[wpv-post-type]' ne 'custom-page-section' ) AND ( '[wpv-post-type]' ne 'custom-post-section' )"]
[wpv-post-link]
[/wpv-conditional]

So putting it all together, you end up with this:

[wpv-conditional if="( '[wpv-post-type]' eq 'custom-page-section' )"]
[wpv-post-link item="@custom-page-section.parent"]
[/wpv-conditional]
[wpv-conditional if="( '[wpv-post-type]' eq 'custom-post-section' )"]
[wpv-post-link item="@custom-post-section.parent"]
[/wpv-conditional]
[wpv-conditional if="( '[wpv-post-type]' ne 'custom-page-section' ) AND ( '[wpv-post-type]' ne 'custom-post-section' )"]
[wpv-post-link]
[/wpv-conditional]

Delete the shortcodes you had in place earlier and use the above code instead.

#1162158

Hi Christian,

Its working now and there should be no more issues, thanks for your help and guides.

My issue is resolved now. Thank you!