I am trying to get Relevanssi to search custom fields. I have set up the index and selected 'visible' for custom fields in Relevanssi (I have also tried 'All').
However, when I check the 'include in search' box of any Toolset custom field and then save the custom field group, the 'include in search' checkbox doesn't stay 'checked' (see screenshot). Neither does the custom field appear in the "Text search in custom fields" area.
The custom fields I am trying to include are within a repeatable group.
Hi, check the discussion in this similar ticket: https://toolset.com/forums/topic/searching-keywords-from-repeating-field-group-is-not-working/page/2/#post-1152641
You must add the Repeating Field Group (as a post type) to the Relevanssi index. However, then you run the risk of direct links to each RFG post appearing as search results, which is probably not what you want. You probably want to show the parent post in the search results when there is a matching custom field value. This requires that you create a WordPress Archive for search, and add a conditional that detects the post type of each search result. When the post type matches the RFG, display the parent post's information. When it does not match the RFG, display the current post's information. I can help if this is confusing or you get stuck.
Thanks Christian - much appreciated. My first task will be for the fields to show up in the search - and unfortunately it's still not working. I have added the repeating group to the Relevanssi post type list (see screenshot) and re-archived - but it doesn't show up in search still. Also, under the column 'Excluded from search?', it still says 'yes'. How do you change this to 'no'? There's no apparent option in the custom group editing area...
Thanks, Nick
The field checkbox state looks like a bug, but as long as you have added the custom field slug in the Relevanssi custom field index area the field can be indexed. To change the RFG to be searchable, you can add the following code to a child theme's functions.php file, or to a new snippet in Toolset > Settings > Custom code:
add_filter( 'wpcf_type', function( $post_type_options, $post_type ) {
if( $post_type == 'faq-and-answers' ) {
$post_type_options[ 'exclude_from_search' ] = false;
$post_type_options[ 'publicly_queryable' ] = true;
}
return $post_type_options;
}, 10, 2 );
Note that the parent post type must be indexed as well as the RFG.
Thanks for your time on this Christian. Unfortunately I am no further along. In fact, when Relevanssi is activated, nothing appears in the search results at all now - not even pages and posts, so I have had to disable it.
I am working locally at the moment, but when the site is on the dev server, perhaps you could take a look to make sure I'm not missing anything?
Thanks again, Nick
I'll take a look. Please add dev login credentials in the private reply fields here.
Okay thanks, I am escalating this issue to my 2nd tier support team now. In my local tests, I'm able to access RFG custom field values in the Relevanssi search using the steps I described earlier, but for some reason yours isn't working the same way. I will try to get some feedback and give you an update as soon as I can.
Hi Christian - apologies but I forgot to let you have the front end password which I have had to reset so that the client can review the site. I have added it to the private message for your reference.
Thanks for the update, I'll keep you posted here as I receive more information.
Hi Christian - I have added additional info to the private message. Thanks, Nick
Thanks for the additional information. I'll keep you posted here, but there's nothing new to share just yet.