As this is article comes up a lot in search results, I wanted to add my experiences.
I prefer coding to plugins whenever it makes sense. Without a plugin, I was not able to search both the post title and the ACF fields for a custom post type. Making changes to functions.php and/or creating a custom WP_Query, I just couldn’t get there.
Using ACF: Better Search, I found it includes ACF fields on the search result page (search.php) but doesn’t work for custom post types (archive-my_post_type.php) or custom WP_Query.
I installed Relevanssi and it offers a simple way to include post types and custom fields. I ran the index and it works perfectly for me.
I got this to work with ACF Pro 5.8.12, using the above code and code from this answer. Here’s what I added to my functions.php:
add_filter('acf/load_value/key=field_5eff2f9949765', 'acf_load_my_defaults', 10, 3);
function acf_load_my_defaults($value, $post_id, $field) {
if ($value === false) {
$value = array();
$value[] = array(
'field_5eff2fac49766' => 'Example Title One',
'field_5eff2fbd49767' => 'Some content for this block'
);
$value[] = array(
'field_5eff2fac49766' => 'Example Title Two',
'field_5eff2fbd49767' => 'Some content for this block'
);
}
return $value;
}
Great support. Same problem, and the solution ‘remove_all_filters()’ did the trick. Thanks, both of you!