A little more info. On further inspection, it looks like some of my fields are getting indexed. The ones that aren’t all appear to be “relationship” ACF fields.
How should Relevanssi index the relationship field?
At a minimum it’d be great if it could index at least the post title of related posts.
Here’s an example use case.
We’re running a web site for a festival. The festival has events and speakers, both of which are custom post types. There’s a relationship field that connects speakers with the events they are speaking at.
Right now, when you search for a speaker by name, you don’t get the events at which they are speaking.
Ok, that’s definitely something you need to teach Relevanssi to do. Fortunately, somebody else has asked this before, and I have some instructions available in the KB.
Thanks! I’ll take a look and see if I can apply it to my situation. I appreciate the quick and helpful response.
I’m making progress but there are a couple of things about the example I’m having trouble understanding.
Here’s the example for reference:
add_filter('relevanssi_content_to_index', 'beautymed_add_product', 10, 2);
add_filter('relevanssi_excerpt_content', 'beautymed_add_product', 10, 2);
function beautymed_add_product($content, $post) {
$tplName = get_post_meta( $post->ID, '_wp_page_template', true );
if ($tplName === 'template-types.php') {
$products = get_field('produits');
foreach ($products as $product) {
$content .= get_field('description', $product->ID);
$content .= get_field('infos', $product->ID);
$content .= get_field('conseils', $product->ID);
}
}
return $content;
}
And here’s what I’m trying to do.
add_filter('relevanssi_content_to_index', 'bookfest_add_participant', 10, 2);
add_filter('relevanssi_excerpt_content', 'bookfest_add_participant', 10, 2);
function bookfest_add_participant($content, $post) {
$participants = get_field('participants', $post->ID);
if($participants){
foreach ($participants as $participant) {
$content .= get_the_title( $participant->ID );
}
}
return $content;
}
Checking for the page template isn’t working for me. I guess my theme is using the default template. So I thought it made more sense to check for the existence of the Participants field. But this isn’t working. I tried removing the “if (participants)” condition and still no dice. Any suggestions?
I think I may have found the problem. I have more than one participant per event and I think the additions to $content need a space between them.
add_filter('relevanssi_content_to_index', 'bookfest_add_participant', 10, 2);
add_filter('relevanssi_excerpt_content', 'bookfest_add_participant', 10, 2);
function bookfest_add_participant($content, $post) {
$participants = get_field('participants', $post->ID);
if($participants){
foreach ($participants as $participant) {
$content .= get_the_title( $participant->ID );
$content .= " ";
}
}
return $content;
}
Yes, adding spaces between the entries is a good idea.