Skip Navigation

[Resolved] Need conditional display of distance

This thread is resolved. Here is a description of the problem and solution.

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 5 years, 5 months ago. 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.

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)

This topic contains 4 replies, has 2 voices.

Last updated by scottL-3 5 years, 5 months ago.

Assisted by: Luo Yang.

Author
Posts
#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?
hidden link

#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!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.