Skip Navigation

[Resolved] Strange issue with conditional comparison of image caption

This support ticket is created 4 years, 2 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.

Our next available supporter will start replying to tickets in about 4.24 hours from now. Thank you for your understanding.

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)

Tagged: 

This topic contains 3 replies, has 3 voices.

Last updated by edF-5 4 years, 2 months ago.

Assisted by: Luo Yang.

Author
Posts
#1794557

Hi there,

I'm encountering a strange issue with a conditional comparison involving the caption of a featured image. Here is my code, which checks whether the featured image caption is empty:

  [wpv-conditional if="( '[wpv-post-featured-image output="caption"]' ne '' )"]
  <p class="spotlight_featured_image_caption">[wpv-post-featured-image output="caption"]</p>
  [/wpv-conditional]

The problem is that if the caption contains one or more double-quotes, the comparison fails. I've added the debug="true" component to the conditional statement, but it doesn't display additional information as it ought to (a separate failure in itself). Note: without a quote in the caption, the debug argument does display the gray box with additional information.

Does this have to do with the fact that the quoted value has quotes in it? Is there a way to escape the quotes in the caption so that Toolset doesn't get confused?

Thank you!

Saul

#1795203

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

The condition itself and the debug info are both being tripped up by the quotes, yes.

There isn't a way to escape the output directly, you'd need to set this up yourself, using the PHP function htmlspecialchars (hidden link).

I haven't tried, but you could register that function at Toolset > Settings > Front-end Content and then simply wrap your existing shortcode in that function within the if attribute.

If that doesn't work, you may have to register a custom shortcode that returns the caption with the quotes replaced by html entities.

#1795219

Hello,

It is a known issue of wpv-conditional shortcode, see our document:
https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/#setting-up-conditional-output-using-the-user-interface
You should avoid using conditions that use special characters like single quotes, double quotes, or dollar signs.

So you can also edit those image caption text, remove the special characters.

#1795677

Thanks, Nigel and Luo. The conditional just needs to test for the presence of text in the image's caption field, so I'll create a custom shortcode that returns true or false.

Thank you again!