Skip Navigation

[Resolved] Conditional with complicated conditions

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

Problem: I would like to use a conditional to test the output of a Content Template using a post ID from a custom field in the current post. It may be empty or it may have some content. I would like to be able to test that value with conditional HTML, but it's not working as expected.

Solution: If you exceed the maximum nesting depth level, the conditional engine will have problems deciphering the sequence of nested quotation marks. Usually the best practice here is to create a custom shortcode that does not require so many nested attributes and shortcodes.

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-custom-functions-in-conditions/#checking-for-empty-post-content
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/

0% of people find this useful.

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

Last updated by rachelP-2 5 years, 7 months ago.

Assisted by: Christian Cox.

Author
Posts
#1280277

Tell us what you are trying to do?
I want to test if the body of a related post is empty.
Here's what i'm putting in the conditional:

[wpv-conditional if="('[wpv-post-body view_template='None' item='[wpv-post-field name='wpcf-current-post-id']']'
eq '' )"] empty body [/wpv-conditional]

but it's not returning anything. Can you tell me why?
Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?
hidden link

#1280367

Hi, it looks like you have exceeded the maximum quotation mark nesting level here. The conditional breaks down because you have single quotes nested inside other single quotes, so it's not able to determine which ones open and which ones close. Ideally you would have single quotes nested inside double quotes or vice versa, but when you start getting beyond that depth level things get tricky. Normally the best way to get around this is to create a custom shortcode or function you can use in this conditional to avoid the need for all those nested quotes.
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-custom-functions-in-conditions/#checking-for-empty-post-content
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/using-shortcodes-in-conditions/

#1280597

That was fun! Thank you!
Here's the shortcode I'm using in my wpv conditional:
function check_related_post_content() {
$post_id = do_shortcode('[types field="current-post-id"][/types]');
$queried_post = get_post($post_id);
$post_content = strlen($queried_post->post_content);
if ($post_content > 1) {
return 1;
} else {
return 0;
}
}
add_shortcode( 'post_with_library_id', 'check_related_post_content' );