Skip Navigation

[Resuelto] Need conditional display of distance

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem:

I want to display distance in search results with the new [toolset-maps-distance] shortcode using the url parameter from the search and the address field from the results.

Solution:

You use shortcode [wpv-conditional] shortcode to check if the distance shortcode's value isn't empty, then display the content, for example:

https://toolset.com/forums/topic/need-conditional-display-of-distance/#post-1151132

Relevant Documentation:

https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/

This support ticket is created hace 6 años. 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

Este tema contiene 4 respuestas, tiene 2 mensajes.

Última actualización por scottL-3 hace 6 años.

Asistido por: Luo Yang.

Autor
Mensajes
#1150877

Tell us what you are trying to do?
I want to display distance in search results with the new [toolset-maps-distance] shortcode using the url parameter from the search and the address field from the results. I want to put the unit after the distance value but I don't want the unit to show if there is no value which is true for all results before a search is performed.

In other words, if I add this to the marker and / or search result template:
<small>Approximately [toolset-maps-distance-value origin_source='url_param' postmeta='wpcf-partner-location-address' unit='mi'] miles</small><br>

I do not want to see:
Approximately miles<br>

when the search hasn't been performed yet.

An idea: what if the [toolset-maps-distance-value] shortcode took parameters for a prefix and suffix? Or, what if it had a closing [/toolset-maps-distance-value] and anything between the open and close only shows if a value is returned? Or, of course, what if I could test the value in the normal conditional? Maybe this is possible but has to be manually entered?

Any tips appreciated. I really cannot use this great new feature until I can conditionally control some text around it.

Is there any documentation that you are following?
I tried to use the normal conditional display but it doesn't seem to have the maps-distance-value available to use.

Is there a similar example that we can see?
Not that I know of.

What is the link to your site?
enlace oculto

#1151132

Hello,

I suggest you use shortcode [wpv-conditional] shortcode to check if the distance shortcode's value isn't empty, then display the content, for example:

[wpv-conditional if = "('[toolset-maps-distance-value origin_source='url_param' postmeta='wpcf-partner-location-address' unit='mi']' NE '')"]
<small>Approximately [toolset-maps-distance-value origin_source='url_param' postmeta='wpcf-partner-location-address' unit='mi'] miles</small><br>
[/wpv-conditional]

More help:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/

#1152099

Hi Luo, I tried this myself and with the code you sent (with the entities replaced with single quotes) and it doesn't seem to work. I think the nested single quotes are supposed to work since the documentation show similar examples but in this case it isn't working. I know the expression evaluates to a non-blank value since it shows the number of miles when I use it without the conditional. Any reason wpv-conditional if wouldn't support this new shortcode yet?

#1152894

Thanks for the feedback, you are right, it is a new shortcode of Toolset map plugin, you can try this:
Dashboard-> Toolset-> Settings-> Front-end Content
in section "Third-party shortcode arguments", add the shortcode name: toolset-maps-distance-value

And test again, please test it and check if it is fixed in your website, thanks

#1153158

My issue is resolved now. Thank you!