The code below will allow the ACF fields (my_text and my_file) to be searched.
add_filter( 'full_text_search_index_post', function( $data, $post_ID ) {
global $full_text_search;
if ( $full_text_search ) {
if ( 'post' === $data['post_type'] ) {
if ( function_exists( 'get_field' ) ) {
$keywords = $data['keywords'];
// Text
$my_text = get_field( 'my_text', $post_ID );
if ( $my_text ) {
$keywords .= "\n" . $my_text;
}
// PDF file (File ID)
$my_file_id = get_field( 'my_file_id', $post_ID );
if ( $my_file_id ) {
$keywords .= "\n" . get_post_meta( $my_file_id, 'full_text_search_search_text', true );
}
$data['keywords'] = trim( $keywords );
}
}
}
return $data;
}, 10, 2 );
* The full_text_search_index_post filter hook has been added since version 2.6.0.
Place this code in your child theme’s functions.php and regenerate your index.