algoliasearch-wordpress
algoliasearch-wordpress copied to clipboard
How do I handle repeater field ACF.
I have a CPT with repeater field created with field type 'User'. I use this to tag a users to the articles. When user performs search, CPT search is working fine, but does not check Meta field 'user' I created. I want to include this, ie search the users that has been tagged.
I have checked the documentation and found the following. `function my_post_attributes( array $attributes, WP_Post $post ) {
if ( 'news' !== $post->post_type ) {
// We only want to add an attribute for the 'speaker' post type.
// Here the post isn't a 'speaker', so we return the attributes unaltered.
return $attributes;
}
// Get the field value with the 'get_field' method and assign it to the attributes array.
// @see https://www.advancedcustomfields.com/resources/get_field/
$attributes['add_users'] = get_field( 'add_users', $post->ID );
// Always return the value we are filtering.
return $attributes;
}`
I have also renabled : Index name: posts_acf-field and Index name: posts_acf-field-group in algolia settings and indexed.
Btw I checked the account and found that this field has been added to, so I think this is related to not showing in results page and autocomplete.
//Make custom fields searchable //alter the settings of the
posts_speakerindex because in the
searchable_postsindex not all posts have the
bioattribute add_filter( 'algolia_posts_speaker_index_settings', 'my_posts_index_settings' ); function my_posts_index_settings( array $settings ) { // Make Algolia search into the 'bio' field when searching for results. // Using ordered instead of unordered would make words matching in the beginning of the attribute make the record score higher. $settings['attributesToIndex'][] = 'unordered(add_users)'; // Make Algolia return a pre-computed snippet of 50 chars as part of the result set. $settings['attributesToSnippet'][] = 'add_users:50'; return $settings; }
Can anyone help me how to include search for repeater field?