Skip Navigation

[Resolved] Conditional for empty field value

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

Problem: I would like to use conditional HTML to display a list element, but only if the "title" custom field is blank.

Solution: Use the following conditional format to prevent extra list elements from being displayed if the field is blank:

[wpv-conditional if="( $(wpcf-title) ne '' )"]
<li>[types field='title'][/types]</li>
[/wpv-conditional]

Relevant Documentation:
https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/

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

Last updated by CSS Web 4 years, 6 months ago.

Assisted by: Christian Cox.

Author
Posts
#1660487

Tell us what you are trying to do?

I need this

  • to show ONLY it there is a value. Ie. hide if empty.
  • [types field='title'][/types]
  • Is there simple conditional logic that I can wrap it in?

    Is there any documentation that you are following?

    None - but I would love some if it exists. My PHP knowledge is low - but on the rise 🙂

    Is there a similar example that we can see?

    No.

    What is the link to your site?

    Password protected during dev.

    #1660489

    Sorry - my message formatted porely 🙁 My fault

    I need this < li > to show ONLY it there is a value. Ie. hide if empty.

    < li > [types field='title'][/types] </ li >

    Is there simple conditional logic that I can wrap it in?

    #1662165
    Screen Shot 2020-06-14 at 11.48.36 AM.png

    Hi, yes you should be able to use a conditional block or conditional shortcode to test if the field value is NOT equal to "blank". If you're using conditional shortcodes, the syntax looks like this:

    [wpv-conditional if="( $(wpcf-title) ne '' )"]
    <li>[types field='title'][/types] </li>
    [/wpv-conditional]
    

    I am attaching an example of the conditional builder settings you can see here.

    #1668833
    Screen-Shot-2020-06-18-at-9.10.31-AM.png

    Aloha Christian,

    My apologies for the slow reply.

    I love both your solutions, esp. the second because in theory, it should remove the < li > element altogether.

    Sadly, I can't seem to get it to work. The empty < li > still shows up.

    Any ideas?

    #1668845

    PS - really appreciate your help and having the Toolset team to turn to when I get stuck.

    Really tremendous support. Much appreciated!

    🙂

    #1668851

    Aloha Christian!

    MY APOLOGIES 🙂

    I just looked at my screenshot above and spotted my VERY rookie error (not deleting the second < li >).

    Very embarrassing!!

    Your code works beautifully!! THANK YOU.

    You the best 🙂

    #1670143

    My issue is resolved now. Thank you!