Skip Navigation

[Resolved] Problem with setting up conditional output on layout

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

Problem:
I have a Custom Field called "Lyrics". I am trying to create a condition where for a post if the Lyrics field is blank then the text

Lyrics

will not display.
Solution:
Conditional statement here:
https://toolset.com/forums/topic/problem-with-setting-up-conditional-output-on-layout/#post-562263
Relevant Documentation:

This support ticket is created 7 years, 3 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 7.00 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 12:00 – 17:00 -
- 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 18:00 – 21:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 7 replies, has 2 voices.

Last updated by Joel Laviolette 7 years, 2 months ago.

Assisted by: Noman.

Author
Posts
#560593

I have a Custom Field called "Lyrics". I am trying to create a condition where for a post if the Lyrics field is blank then the text <h3>Lyrics</h3> will not display.

I have the code set like this, but it is just hiding the Lyrics header regardless of whether there is anything contained in the Custom Field:

[code]
<p>[wpv-conditional if="( $(wpcf-lyrics) eq '.' )"]</p>
<h3>Lyrics:</h3>
<p>[/wpv-conditional]</p>
[/code]

I'm guessing that the "eq" above maybe stands for "equals" in which case I understand why there is an issue. How do I make the above code say "if wpcf-lyrics CONTAINS ANYTHING then output blah blah blah.

Thanks!

#560773

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Joel,

Thank you for contacting Toolset support. Yes, eq means equal. But in your case you need to set NOT equal condition. Please use this updated code:

<p>[wpv-conditional if="( $(wpcf-lyrics) ne '' )"]</p>
<h3>Lyrics:</h3>
<p>[/wpv-conditional]</p>

Use empty quotes if the Lyrics field is blank, no need to write anything in ne’’.

Doc - Checking fields and other elements for Empty/Non-empty Values:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/

Thank you

#561592
Screen Shot 2017-08-19 at 4.34.42 PM.png
Screen Shot 2017-08-19 at 4.36.20 PM.png

Thanks for the reply. For some reason this is still not working for me. If I use the conditional then the <h3>Lyrics</h3> disappears regardless of whether there is content in the custom field.

I am attaching a couple screenshots of my layout and the output that I am getting.

In the sceenshot of the page above the words "Do you know my name?" should be the Lyrics header. "Do you know my name" is the content of the "lyrics" custom field. That page can be seen here:
hidden link

One secondary question-when I export the custom fields in a CSV, those fileds are lableled with an prefix. IE, the field is: cf_wpcf-lyrics instead of wpcf-lyrics. I have tried both in this conditional with no difference in the output.

Thanks for your continued help.

#561881

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello Joel,

From the screenshots, condition looks fine and should work as expected.

1. Please delete all sort of caches in your site plugin cache (WP Fastest Cache), CDN / server cache (if any), browser cache too.

2. If still issue persists, please provide temporary website WP-admin and FTP info for your site so I can debug further. Your next answer will be private which means only you and I have access to it.

=== Please backup your database and website ===

✙ I would additionally need your permission to de-activate and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important.

✙ Please add the Links to the [Layout] edit screen where we can see condition and the issue.

Thank you

#562263

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Condition.png

Hello Joel,

I have checked the condition in your layout, you were using dot “.” in the condition instead of empty quotation marks. I have updated the condition (see attached screenshot) and it is working as expected.

Please check here: hidden link

Thank you

#562578

Thanks so much for fixing the issue. However I am confused, as you can see from my above screenshot that I didn't have "." on the screen shot there. I did try to search for a period in a much earlier attempt. This is the second time I have reached out to support where it has seemed like I have made a change only to find that the change (perhaps also?) needed to happen somewhere else. This is even after I cleared the cache.

So is there somewhere else besides looking there in the layout->Edit Layout where I should have checked for the change? I'd like to not have to keep bothering you guys with issues if I should be looking somewhere other than where I am looking or if perhaps the edits get propagated somewhere else that I should be checking. Thanks.

#562674

Noman
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hello,

There were some special characters when I opened the visual editor cell, that’s why dot was not displaying in screenshot. I just re-added the condition and it works. This is the only change I have done.

Thank you

#565425

Thank you for your help!