Include ACF field in autocomplete results
-
I’ve setup your plugin to index my custom post type “products” as well as the custom taxonomy for product categories.
The Autocomplete functionality correctly displays my “products” in the search results, but only the title, because there is no default “content” field for this post type, but rather there is an ACF field called “product_description”. I want that “product_description” to display in the Autocomplete results.
I have successfully followed your instructions to push the “product_description” ACF field out to the Algolia platform, and I can see that field in the Algolia UI, so that part is good.
My problem is in getting that “product description” added into the Autocomplete output in place of the default “content”.
I tried editing the autocomplete.php file in various ways (per some online documentation) to replace the references to “content” with references to “product_description” but that doesn’t seem to be working.
Here’s what I currently am trying in autocomplete.php for lines 22-35:
<a class="suggestion-link" href="{{ data.permalink }}" title="{{ data.post_title }}"> <# if ( data.images.thumbnail ) { #> <img class="suggestion-post-thumbnail" src="{{ data.images.thumbnail.url }}" alt="{{ data.post_title }}"> <# } #> <div class="suggestion-post-attributes"> <span class="suggestion-post-title">
data._highlightResult.post_title.value
</span> <# if ( data._snippetResult['product_description'] ) { #> <span class="suggestion-post-content">data._snippetResult['product_description'].value
</span> <# } #> </div> <?php do_action( 'algolia_autocomplete_after_hit' ); ?> </a>Again, I basically just replaced “content” references with “product_description”. But that fails to product any result, even though the data is out in the Algolia platform.
Here is the page: https://wordpress-1341165-4918007.cloudwaysapps.com/search-test/
What am I missing?
The page I need help with: [log in to see the link]
- You must be logged in to reply to this topic.