I'm currently using Algolia's Search plugin within Worpdress. I've managed to push some custom fields and their values to custom attributes within Algolia. Now, I'm trying to include a custom attribute named 'program_description' in my search results.
By default, the search is only returning the value of the 'post_title' and 'content' attributes. I'm interested in replacing the 'content' attribute output with with my custom attribute's output('program_description').
I thought I would simply modify the instantsearch.php template by adding 'program_description' to the attributes array like so:
<div class="ais-hits--content">
<h3 itemprop="name headline"><a href="{{ data.permalink }}" title="{{ data.post_title }}" itemprop="url">{{{ data._highlightResult.post_title.value }}}</a></h3>
<div class="ais-hits--tags">
<# for (var index in data.taxonomies.post_tag) { #>
<span class="ais-hits--tag">{{{ data._highlightResult.taxonomies.post_tag[index].value }}}</span>
<# } #>
</div>
<div class="excerpt">
<p>
<#
var attributes = ['program_description', 'content', 'title6', 'title5', 'title4', 'title3', 'title2', 'title1'];
var attribute_name;
var relevant_content = '';
for ( var index in attributes ) {
attribute_name = attributes[ index ];
if ( data._highlightResult[ attribute_name ].matchedWords.length > 0 ) {
relevant_content = data._snippetResult[ attribute_name ].value;
}
}
relevant_content = data._snippetResult[ attributes[ 0 ] ].value;
#>
{{{ relevant_content }}}
</p>
</div>
</div>
In doing so, none of my results are returned and I'm met with the following console error:
Uncaught TypeError: Cannot read property 'matchedWords' of undefined
Any help would be greatly appreciated.