Skip Navigation

[Resuelto] instead of toolset excerpt, display relevanssi excerpt in results

This support ticket is created hace 5 años, 10 meses. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Este tema contiene 4 respuestas, tiene 2 mensajes.

Última actualización por Ido Angel hace 5 años, 10 meses.

Asistido por: Nigel.

Autor
Mensajes
#1184120

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

#1184139

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+00:00)

Hi 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.

enlace oculto

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?

#1184158

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:

enlace oculto

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 🙂

Cheers!
Ido

#1184240

Nigel
Supporter

Idiomas: Inglés (English ) Español (Español )

Zona horaria: Europe/London (GMT+00:00)

The solution is simpler than I thought.

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.

#1184259

Works like a charm!!! Thanks Nigel!