ACF: Indexing files from File fields

[ad_1]

Good morning,

Relevanssi can index attachment contents from files linked to posts with ACF File fields. This does not happen automatically but requires some extra code.

add_filter( 'relevanssi_content_to_index', 'rlv_get_acf_file', 10, 2 );
add_filter( 'relevanssi_excerpt_content', 'rlv_get_acf_file', 10, 2 );

function rlv_get_acf_file( $content, $_post ) {
    $file = get_field( 'pdf_file', $_post->ID );
    if ( is_array( $file ) && isset( $file['ID'] ) ) {
        $content .= ' ' . get_post_meta( $file['ID'], '_relevanssi_pdf_content', true );
    }
    return $content;
}

I added the code to your site and rebuilt the index. But I get no results when searching for a pdf file of a post.

Can you help me?
Thank you so much

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer