hey,
so - the custom search i built is showing the post excerpt in the results.
but - i'm using relevanssi, and i see that it has a very unique way of displaying a unique excerpt which includes:
1) the paragraph from the body which includes the search terms in the free search input box
2) the search term is highlighted
while i managed to highlight the search term in the toolset excerpt (with the help of an external hilighting jquery plugin), still some of the excerpts don't present the actual search term, which is a bit confusing.
is there a way to create a shortcode or a function which will take the excerpt created by relevanssi to the toolset search results?
thanks!
Ido
I haven't tried to implement it, but from the Relevanssi documentation it appears that you should be able to use functions such as relevanssi_highlight_terms to achieve what you want, putting it inside a custom shortcode so that you can use it in the Loop Output section of a View.
hidden link
To know how exactly it works means trying it out to see.
Do you want to give it a go and if you get stuck let me know and I will take a look myself?
Dear Nigel 🙂
I got stuck at the doorstep... i'm not an expert in using functions, but am ready to learn.
Would you be willing to help? I'd appreciate it so much.
I'm just emphasizing - I managed with the highlighting. You can see here:
hidden link
What I wanted to achieve is to replace the view excerpt with the relevanssi excerpt, and I wanted that in thinking that they are different, that the relevanssi excerpt is taking a specific paragraph from the post body which contains the search term. But I might be wrong, and then we're all good 🙂
Looking at the Relevanssi functions I determined that they were unlikely to work in the context of a View. I believe that on normal WordPress search pages (where you are not using Toolset), Relevanssi works by filtering the excerpt to replace the normal text, including adding highlighting using strong tags (which I think you can modify in the Relevanssi settings).
It seems that the Views shortcode wpv-post-excerpt outputs an excerpt without passing through the same filters that Relevanssi depends upon, so my solution is to create a new shortcode to output the excerpt which does, i.e.
/**
* Output Relevanssi excerpt with search term highlighting
*/
add_shortcode('relevant', function () {
$excerpt = get_the_excerpt();
return $excerpt;
});
Use the [relevant] shortcode in place of the wpv-post-excerpt shortcode in your Loop Output section.