Skip Navigation

[Resolved] Trouble using single and double quotes in wpv-conditional

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

Problem: I am trying to use wpv-conditional to test for an empty value in an email custom field. If I include another shortcode inside the wpv-conditional, it does not work as expected.

Solution: Add the following line to your wp-config.php file to disable the PCRE regex engine:

ini_set('pcre.jit', false);
This support ticket is created 5 years, 11 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 5 replies, has 2 voices.

Last updated by jeffS-2 5 years, 11 months ago.

Assisted by: Christian Cox.

Author
Posts
#1162348

I am trying to: use an email address from a types field (for an event CPT) to make the event's speaker's name a link to their email - but only if the email field is not empty.

    [wpv-conditional if="( NOT(empty($(wpcf-speakers-email))) )"]<a href="mailto:[types field='speakers-email' raw='true'][/types]?subject=Inquiry from CNSV talk">[types field="name-of-speaker"][/types]</a>[/wpv-conditional]

I cannot get this to display correctly using wpv-conditional; however, it does work correctly using wpv-if.
Is there a better/easier way to do this?

Thanks,
Jeff Safire
--------------

#1162492

Hi, you can try testing for a non-empty string like this:

[wpv-conditional if="( $(wpcf-speakers-email) ne '' )"]<a href="mailto:[types field='speakers-email' raw='true'][/types]?subject=Inquiry from CNSV talk">[types field="name-of-speaker"][/types]</a>[/wpv-conditional]

If that doesn't work, add the debug="true" attribute to the wpv-conditional shortcode like this, and let me know what you see on the front-end of the site:

[wpv-conditional if="( $(wpcf-speakers-email) ne '' )" debug="true"]<a href="mailto:[types field='speakers-email' raw='true'][/types]?subject=Inquiry from CNSV talk">[types field="name-of-speaker"][/types]</a>[/wpv-conditional]
#1162648
Screen Shot 2018-12-09 at 6.39.26 PM.png

Hey, Christian -

As I expected, using (wpcf-xxx ne '') works the same as using NOT(empty($(wpcf-xxx))). As you can see from the debug output, the comparison executes correctly; the problem is with the use of mixed single and double quotes inside the <a> tag. I've tried reversing the single for doubles, and adding quotes around "[types...][/types]" but that didn't help.

I have had trouble with this in the past with wpv-if but eventually got it to work with the correct arrangement of quotes. I can't seem to make that happen with wpv-conditional, which doesn't make sense to me because the problem is not within the wpv-conditional definition (brackets). However, to reiterate, if I simply replace [wpv-conditional...][/wpv-conditional] with [wpv-if...][/wpv-if] it works as expected.

Here is the View output:

GrokStyle: Deep Learning and the Future of Visual Search (THE POST TITLE DISPLAYS CORRECTLY HERE)
[types field="name-of-speaker"][/types] (THIS <>strong>SHOULD BE NAME OF SPEAKER WITH LINK)
####################
wpv-conditional attributes
####################
Array
(
[if] => ( $(wpcf-speakers-email) ne '' )
[debug] => true
)

####################
Debug information
####################
--------------------
Original expression: ( $(wpcf-speakers-email) ne '' ) (NE TO EMPTY STRING)
--------------------
--------------------
Converted expression: ( 'sbell@grokstyle.com' ne '' ) (THIS RESOLVES CORRECTLY AS SPEAKER'S EMAIL)
--------------------

Thanks,
Jeff Safire

#1162673

Christian -

I just switched from PHP 7.03 to 5.6.20, and everything works correctly. I know little about the difference between PHP 7.0.3 and 5.6.20. Unfortunately, the whole point of this exercise of converting this content template to use wpv-conditional in place of wpv-if is to clean it up before committing to PHP 7.x because I have interspersed wpv-if and wpv-conditional in several content templates for this site.

So, it appears something different in PHP 7 affects the quotes usage/parsing inside statements containing [types][/types].
Maybe?

Jeff
----------

#1162910

I don't see anything inherently wrong with this syntax. In fact, I copied it into Content Templates on two local test sites, running PHP 7.0.31 and 7.2.8, and replaced a couple of custom field slugs:

[wpv-conditional if="( $(wpcf-book-email) ne '' )"]<a href="mailto:[types field='book-email' raw='true'][/types]?subject=Inquiry from CNSV talk">[types field="author-name"][/types]</a>[/wpv-conditional]

The conditional works as expected on both sites, and the mailto link is shown with the custom field text. So there must be something else going on I'm not fully understanding. As a quick test, try adding this line to your wp-config.php file just before the line "That's all, stop editing!"

ini_set('pcre.jit', false);

Save the file and upload it to your server, then test again. If the problem is resolved, then you're bumping into an issue with regex on specific versions of PHP. Disabling the PCRE JIT regex engine will fix that problem with minimal side effects. If the problem is not resolved, then we need to do some additional investigation. Temporarily switch to a default theme like Twenty Seventeen, deactivate all plugins except Types and Views, and test again. If the problem is resolved, reactivate your theme and other plugins one by one until the problem returns.

#1163475

My issue is resolved now. Thank you!