Support

Account

Home Forums General Issues ACF and Relevanssi

Solving

ACF and Relevanssi

  • Hi,

    I have created a pages with advanced custom field . The pages have no content or excerpt, all content is added to the custom field.

    At the search it appear the name of the page but no other text that may contain the word appears.

    I have configured within the plugin, Indexing Options: designated ACF-field-group and ACF-field , although they appear as public. And in “Custom field to index: all”

    I read that I have to make an excerpt with my custom fields but not how to do it

    What should I do? Thank you

  • Hi @cenobita

    Yeah Relevanssi can only create an excerpt for you if you use the default content editor.

    To create your own excerpt or snippet of text you can just edit your themes search.php file and replace the_excerpt(); with your own function or get_field if you want it to show a specific fields output.

  • Thanks Jonathan,

    I am using the following function. Slider is one of my custom fields:

    add_filter('relevanssi_excerpt_content', 'custom_fields_to_excerpts', 10, 3);
    function custom_fields_to_excerpts($content, $post, $query) {
       
        $custom_field = get_post_meta($post->ID, 'slider', true);
        $content .= " " . $custom_field;
       
        return $content;
    }

    But nothing still . Are you any ideas to add function ?

    Best regards

  • there are some solutions at http://www.relevanssi.com/knowledge-base/add-custom-fields-search-excerpts/#comment-2399476112

    however i have found nothing yet that deals successfully with repeater fields or flexible content. The relevannsi developer says an ACF dev should be able to figure it out if taking the info at the above link into account.

    I use acf and relevannsi on pretty much every site, so a way to get good search results for ACF from relevannsi is really important to me, but as a front end dev i feel out of my depth at this point.

    A generic example for getting flexible content to show in snippets and one for repeaters would hopefully be all I would need to sort the rest out myself.

    Can anyone help?

  • Hi, I’ve just got some more grey hairs and got the code from the Relevassi blog post about this working so it will use custom fields in it’s excerpt. With this code and “custom search result snippets” turned on, it will highlight the search term.
    Hope this helps others!!

    add_filter('relevanssi_excerpt_content', 'custom_fields_to_excerpts', 10, 3);
    function custom_fields_to_excerpts($content, $post, $query) {
    
    $custom_field = get_post_meta($post->ID, 'normal_custom_field', true);
    $content .= " " . $custom_field;
    $custom_field = get_post_meta($post->ID, 'normal_custom_field2', true);
    $content .= " " . $custom_field;
    
    if($fields){
    foreach($fields as $custom_field){
    $content .= " " . $custom_field['repeater_sub_field_1'];
    $content .= " " . $custom_field['repeater_sub_field_2'];
    }
    }
    $fields = get_field('page_content', $post->ID);
    if($fields){
    foreach($fields as $custom_field){
    
    if($custom_field['acf_fc_layout'] == 'layout_name_1'){
    $content .= " " . $custom_field['sub_custom_field'];
    $content .= " " . $custom_field['sub_custom_field2'];
    
    } elseif ($custom_field['acf_fc_layout'] == 'layout_name_2'){
    $content .= " " . $custom_field['sub_custom_field'];
    }
    }
    }
    return $content;
    }
Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘ACF and Relevanssi’ is closed to new replies.