Advanced custom fields integration in Wordpress

Hi! I’ve been trying to use the Advanced Custom Fields integration (https://community.algolia.com/wordpress/advanced-custom-fields.html) and, even though I’ve been able to push the fields to the index, when I make a search in the web I have no results.

I’ve created a custom field called keywords_list to add keywords in all pages and they are shown in the dashboard’s indexes:
30 PM

But when I write “veronica” into the search input, nothing happens:
26 PM

Here’s the full code I’m using:

add_filter( 'algolia_post_shared_attributes', 'my_post_attributes', 10, 2 );
add_filter( 'algolia_searchable_post_shared_attributes', 'my_post_attributes', 10, 2 );
/**
 * @param array   $attributes
 * @param WP_Post $post
 *
 * @return array
 */
function my_post_attributes( array $attributes, WP_Post $post ) {
    $attributes['keywords_list'] = get_field( 'keywords_list', $post->ID );
    return $attributes;
}

add_filter( 'algolia_posts_keywords_index_settings', 'my_posts_index_settings' );
/**
 * @param array $settings
 *
 * @return array
 */
function my_posts_index_settings( array $settings ) {
    $settings['attributesToIndex'][] = 'keywords_list';
    return $settings;
}


add_filter( 'algolia_posts_keyword_index_settings', 'my_keyword_index_settings' );
/**
 * @param array $settings
 *
 * @return array
 */
function my_keyword_index_settings( array $settings ) {
    $customRanking = $settings['customRanking'];
    array_unshift( $customRanking, 'desc(keywords_list)' );
    $settings['customRanking'] = $customRanking;
    return $settings;
}

What am I doing wrong?
Thanks!
Vero

1 Like

I’ve found that it works if I don’t use my own customized search page/autocomplete (wp-content/themes/mytheme/algolia). I deleted the folder and now, when I write “veronica” the results comes up. So now I need to figure out how to use my own templates and keep it working :slight_smile:
If you have any clue, I’ll appreciate it.

1 Like

I fear that guide is a bit deprecated.
Also there is an open issue to help users integrate custom fields: https://github.com/algolia/algoliasearch-wordpress/issues/630

Please track that issue. And feel free to continue the discussion there.
Let us know what you are trying to achieve so that we can cover it in the examples that are coming.

Cheers,

1 Like

Thanks! I’ve figured out how to make it work. Was a problem with the autocomplete.php file that I’d modified.
Cheers!

1 Like