Hello,
I’m having an issue indexing content from an ACF relationship field.
I’ve followed tutorials found in previous support cases with no luck.
For context:
On the product post type I have an ACF relationship named “company_link” field with a relationship to a custom post type “Company”.
I have live search implemented on the product catalog page and my goal is to be able to search a post title from the related company and display the products.
I’ve already tried adding this function however i’ve had no success.
add_filter(‘asp_post_content_before_tokenize_clear’, ‘asp_post_content_before_add_acf_relationship’, 10, 2);
function asp_post_content_before_add_acf_relationship($content, $post) {
$field_name = ‘company_link’;
$index_title = true; // To index the related post title
$index_content = true; // To index the related post content
// —————————————————————-
$items = get_field($field_name);
if ( is_array($items) ) {
foreach ($items as $item) {
if ( isset($item->ID) ) {
if ( $index_title ) {
$content .= ‘ ‘ . get_the_title($item->ID);
}
if ( $index_content ) {
$content .= ‘ ‘ . apply_filters(‘the_content’, get_post_field(‘post_content’, $item->ID));
}
}
}
}
return $content;
}
Any assistance would be greatly appreciated!
Thanks,
Alex