Skip Navigation

[Resolved] Need help with setting up search for CPTs

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

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

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 44 replies, has 3 voices.

Last updated by jesseH-3 3 years, 5 months ago.

Assisted by: Shane.

Author
Posts
#1762745

Hi, I am trying to set up a search for my site. I have read the documentation as well as several forum threads and I am thoroughly confused.
I installed Relevanssi and followed the instructions to enable the CPTs and the custom fields, and built the index, but the search is not giving me results from those CPTs. I am using a default WP search field.
Can someone please work with me to determine why this isn't working? I appreciate your help.

#1762777

Hello, normally you will need to set up a Toolset WordPress Archive for the search results page in order to display all your custom post search results along with standard post results. To set this up, go to Toolset > WordPress Archives and create a new archive. Assign this WordPress Archive to the Search Results page, choose the appropriate post types for its Content Selection, and you can design the results loop using the Block Editor or the classic editor. Then your design should appear when search results are displayed on the site.

Let me know if you have additional questions about that.

#1762783

Thank you so much, maybe those instructions are obvious to others but they weren't to me.

Search now appears to be working correctly except it isn't returning anything for data in my repeatable field groups. I read a few forum posts but it wasn't clear to me whether searching for data in repeatable groups should work out-of-the-box or whether I had to add some custom functions.

I've enabled indexing of the repeatable field group. But if I check "Include in search" in any of the fields inside that repeatable group, the setting doesn't stick. I've added the custom fields within that repeatable group (starting with wpcf-) to the list of custom fields in the Relevanssi settings. But no luck.

#1763649

Okay there is an open issue related to the checkbox not persisting for "include in search". I am connecting this ticket to our internal bug tracker so I can keep you posted as work progresses to resolve this issue.
However, you should be able to index these fields even if the checkbox does not persist. See this other ticket for an explanation: https://toolset.com/forums/topic/text-search-for-custom-fields-in-repeatable-group/
You'll need to adjust your search results archive to display the parent post instead of the RFG post in search results. Note that you must add the RFG post type to your Relevanssi index as well as each custom field inside that RFG you want to index.
Let me know if you have questions about this.

#1763745

Thanks Christian.

Can you clarify how to adjust my search results archive to display the parent post instead of the RFG post? I did look at the post you referenced but I can't see the screenshots. So I am not sure how to do this step.

And I have already added the RFG post type to the Relevanssi index and added each custom field from inside the RFG to my index. So that should be done and ready to go.

#1764317

There's nothing much in the screenshots that is relevant to modifying the search results, they are more about configuring the fields for indexing. The process to update the archive results involves creating two conditionals in the loop of the archive: one to display non-RFG posts and another to display RFG posts. Depending on whether you use the classic editor or the Block Editor, the process for setting up conditionals is different. The conditional should test the post type of the current post. RFG posts will have a post type slug that corresponds to the slug of the RFG. If the conditional is true, you need to display the parent post using the "item" attribute and the "@rfg-slug.parent" syntax, like so:

[wpv-conditional if="( '[wpv-post-type]' ne 'rfg-slug' )"]
Show this content if the post type slug is not the same as the RFG slug<br />
Title: [wpv-post-title]<br />
Title with link: [wpv-post-link]<br />
Custom field from post: [types field="post-field-slug"][/types]<br />
[/wpv-conditional]
 
[wpv-conditional if="( '[wpv-post-type]' eq 'rfg-slug' )"]
Show this content if post type slug is the same as the RFG slug<br />
Title: [wpv-post-title item="@rfg-slug.parent"]<br />
Title with link: [wpv-post-link item="@rfg-slug.parent"]<br />
Custom field from RFG: [types field="rfg-field-slug"][/types]<br />
Custom field from parent post: [types field="parent-field-slug" item="@rfg-slug.parent"][/types]<br />
[/wpv-conditional]

You must replace rfg-slug with the slug of this RFG, which you can find when you edit the custom field group that contains the RFG in Toolset > Custom Fields > Post Fields. In the RFG section, you can display fields from the RFG using the standard Types field syntax. To display fields from the parent post, you must include the item attribute and the "@rfg-slug.parent" syntax in a Types field shortcode.

Let me know if this isn't clear or if it's not working as expected and I can take a closer look.

#1764353

I created a new loop using your code above as reference, but I am still not getting any results when I search for data in a field that's in my RFG.
Even without the customization of the loop above, should I be getting some results when searching for data from a field within the RFG? Because I'm getting nothing.
Can I give you login access? What info do you need from me, I can give you as many details as you need – list of fields and RFGs, what's in my Relevanssi index, etc.

#1764513

You may or may not be supposed to see "something" without the customizations I mentioned, it depends on what blocks or shortcodes you have included in the loop of the archive. Login access will be most helpful. I'm activating private reply fields here so you can share those credentials securely. Please let me know what search term you are testing with, and point me towards at least one missing post you would expect to find in the search results for that search term. I'll take a look and give you some feedback.

#1764625

Got it, thanks. I'm finding that a custom search View will include the RFGs in search results, but the search results archive does not behave the same way. I created a Draft post containing a test View that shows this behavior in a View:
hidden link

It seems that these two should produce similar results, but that is not the case here. Let me continue to investigate and I will give you another update tomorrow since my day is closing here.

#1767471

I'm having trouble reproducing this in my own local tests. Locally, the search archive displays these RFG results when I add them to the search index. Something is different in your site, and I'm not sure what it is. Is it possible for me to create a clone of your site using the Duplicator plugin? I would like to run some additional results locally so I don't break your live site. Please let me know if it is okay to install the plugin and create this site clone to run those tests.

#1769595

Thanks so much for your help. Yes, please go ahead and use Duplicator to create a clone of the site.

#1769915

Thanks, I have created the site clone and removed the plugin from your live site. I'll continue to run tests and give you an update tomorrow.

#1771329

I've spent some time trying to isolate any difference between our sites that might be responsible for the different behavior we are experiencing, but I've exhausted all the options I'm aware of. Let me ask my 2nd tier support team to take a closer look. They will be able to dive deeper into the plugin's source code and the contents of your database while monitoring code execution step-by-step. Hopefully this will lead to a better understanding of what's happening here, and I will give you an update as soon as I have more pertinent information. Thank you for your patience as we work on this issue.

#1771365

Sounds frustrating! Thanks for your help and I look forward to a solution.

#1776441

Hi, my team leader was able to provide an example code snippet for me late today but I didn't get a chance to test it out yet. I'll give you an update early tomorrow to let you know whether it's working or not in my setup. Thanks for your patience.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.