ACF Relationship field hook

Home Forums Product Support Forums Ajax Search Pro for WordPress Support ACF Relationship field hook

This topic contains 1 reply, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 1 year, 4 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #40531


    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!


    Ernest Marcinko
    Ernest Marcinko

    Hi Alex,

    There is no 100% guarantee for proper indexing of the relationship fields.
    The code seems to be all right to me, so can you please make sure that you are using the index table engine, and if it is indeed enabled. Also, after adding this custom code make sure to re-create the index table, so that the relationship fields are picked up.

    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘ACF Relationship field hook’ is closed to new replies.