Adding categories to autocomplete content for given pages/posts


I’m rather new to Algolia, so please excuse me if i’m asking an obvious or easy question. I’m using the latest versions of both WordPress and Algolia. Currently i’m styling my own search bar results and so far it’s going well. Unfortunately, I’ve been unable to add categories to the description of the results, for example:

As detailed in the screenshot, I have the title called and the content, but I am wondering if it’s possible to also call the Categories of that post in the description. My autocomplete post template code is basically vanilla Algolia but can be seen on this pastebin: <script type="text/html" id="tmpl-autocomplete-post-suggestion"> <a class="su -

I’ve tried searching but can’t find any documentation on this, any help would greatly be appreciated! Thank you!

Hi @Aaron3, did you try to follow our guide on customizing the autocomplete template for Wordpress? Here it is: Customize Autocomplete drop-down

If your objects in your index have a categories attribute then you can definitely copy paste some lines from your template, change them to categories and see what happens. Since categories are maybe stored in an array, you might have to go over this array using Looping though an index in template? - #10 by vvo thanks!

Hi @vvo, I’ve looked at that guide but i’m a beginner and still trying to figure my way around Algolia, so this page didn’t really help as I’m unsure which arrays are available, ones such as:

 {{{ data._snippetResult['content'].value }}}

This quite obviously calls the content for the autocomplete dropdown, i’ve tried using things such as:

{{{ data._snippetResult['categories'].value }}}


{{{ data._snippetResult['category'].value }}}

Unfortunately both of them just seem to break the search results.

I’m assuming i’ll have to make my own array, which is a whole other question! Are there any pre-existing calls or arrays I can enter in there to pull the category? I know that categories show in the search separate, is there a way to utilise that portion of Algolia for what I would like to accomplish?

I managed to figure this out after trying various things, the code to display the category is:

<span class="suggestion-post-content">{{ data.taxonomies.category }}</span>


Thanks for your help!