Skip Navigation

[Resolved] Using attribute tags in conditional statements

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

Problem:

Find another way to write [wpv-conditional if="( '[wpv-attribute name='boxxy-description']' ne '' )"] that would not fail if boxxy-description contains a quote or single quote.

Solution:

It is not recommended to pass quotes or single quote in the shortcode attribute values.

The client has fixed it by custom codes, see details here:

https://toolset.com/forums/topic/using-attribute-tags-in-conditional-statements/#post-1278479

Relevant Documentation:

This support ticket is created 5 years, 6 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 3 replies, has 2 voices.

Last updated by webadmins 5 years, 6 months ago.

Assisted by: Luo Yang.

Author
Posts
#1277909

I am trying to:
Find another way to write [wpv-conditional if="( '[wpv-attribute name='boxxy-description']' ne '' )"] that would not fail if boxxy-description contains a quote or single quote. Can we write this like [wpv-conditional if="( $wpv-attribute-boxxy-description ne '' )"]? Or something similar?

Link to a page where the issue can be seen:
hidden link

I expected to see:
"Learn about picking and eating summer's sweet treat!" under "Stone Fruit" widget.

Instead, I got:
Nothing under Stone Fruit widget.

#1278005

Hello,

There isn't such a built-in feature within [wpv-conditional] shortcode, and it is not recommended to pass quotes or single quote in the shortcode attribute values.

In your case, I suggest you try to create a custom shortcode to check the attribute value is not empty, then output simple value, for example:
- attribute "boxxy-description" value is not empty, return value 1
- attribute "boxxy-description" value is empty, return value 0

Then follow our document to use above custom shortcode insider wpv-conditional shortcode:
https://toolset.com/documentation/user-guides/shortcodes-within-shortcodes/#third-party-shortcode-arguments

Section "Third-party shortcode arguments"

#1278479

Hi thank you for responding, I didn't create a shortcode but a hook on save_post that converts quotes to the appropriate html characters. When the items are saved to database they are escaped with a back slash. This is great for database storage; however, it just doesn't work for properly dealing with the data on the client side. The hook works and now I can add both quotes and apostrophes. 🙂

#1278481

My issue is resolved now. Thank you!