Skip Navigation

[Resolved] Conditional Output within Views Not Working as I understand the Documentation

This support ticket is created 3 years, 10 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 5 replies, has 2 voices.

Last updated by Stephen 3 years, 10 months ago.

Assisted by: Shane.

Author
Posts
#1966855

I have a CPT: "Projects" with which I have associated CF group: "Projects". I have a view with your deprecated yet still supported Toolset Views that has a loop editor of the following:
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop>
<div><ul class="fs-film-li">[wpv-conditional if="( $(wpcf-project-distributor) eq '' )" evaluate="false"]

  • Distributor: [types field='project-distributor'][/types]
  • [/wpv-conditional]
    [wpv-conditional if="( $(wpcf-project-director) eq '' )" evaluate="false"]

  • Director: [types field='project-director' item='$current_page'][/types]
  • [/wpv-conditional]
    [wpv-conditional if="( $(wpcf-project-writer) eq '' )" evaluate="false"]

  • Writer(s): [types field='project-writer' item='$current_page'][/types]
  • [/wpv-conditional]
    [wpv-conditional if="( $(wpcf-project-producer) eq '' )" evaluate="false"]

  • Producer(s): [types field='project-producer' item='$current_page'][/types]
  • [/wpv-conditional]
    [wpv-conditional if="( $(wpcf-project-executive-producer) eq '' )" evaluate="false"]

  • Executive Producer(s): [types field='project-executive-producer' item='$current_page'][/types]
  • [/wpv-conditional]
    [wpv-conditional if="( $(wpcf-project-cast) eq '' )" evaluate="false"]

  • Cast: [types field='project-cast' item='$current_page'][/types]
  • [/wpv-conditional]

    </div>
    </wpv-loop>
    <!-- wpv-loop-end -->
    [/wpv-items-found]
    [wpv-no-items-found]
    [wpml-string context="wpv-views"]No items found[/wpml-string]
    [/wpv-no-items-found]
    [wpv-layout-end]

    I've attempted to utilize the documented wpv-conditional statement ( [wpv-conditional if="( empty($(wpcf-test-field)) )"]This field is empty or does not exist[/wpv-conditional] ) to no avail.

    My goal is super simple: we need to have fields output for a specific CPT post that has missing data (empty field) in it to have the associated moniker not rendered (visible) on the display output of the view. Here is some debug from one field (distributor) on a post:
    ####################
    wpv-conditional attributes
    ####################
    Array
    (
    [if] => ( $(wpcf-project-distributor) = '' )
    [evaluate] => false
    [debug] => true
    )

    ####################
    Debug information
    ####################
    --------------------
    Original expression: ( $(wpcf-project-distributor) = '' )
    --------------------
    --------------------
    Converted expression: ( '' = '' )
    --------------------

    Is there any documentation that you are following?
    https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-conditional
    https://toolset.com/forums/topic/hide-types-field-if-empty/

    Is there a similar example that we can see? I don't know of one

    What is the link to your site? Already supplied that in request form

    #1967247

    Shane
    Supporter

    Languages: English (English )

    Timezone: America/Jamaica (GMT-05:00)

    Hi Stephen,

    Thank you for getting in touch.

    Would you mind providing me with a link to the page where I can see the issue ? Also if possible can you provide the login as well ?

    Mainly because if you are using this below.

    [wpv-conditional if="( empty($(wpcf-test-field)) )"]This field is empty or does not exist[/wpv-conditional] 
    

    Then it should work, so I would like to see first hand what happens. Please also send me a link to the page that this occurs on as well.

    Thanks,
    Shane

    #1968391

    Shane
    Supporter

    Languages: English (English )

    Timezone: America/Jamaica (GMT-05:00)

    Hi Stephen,

    I did a quick test and the shortcode works as intended. Essentially the statements you have work fine.

    Take a look at my example below.

    [wpv-conditional if="( NOT(empty($(wpcf-project-distributor)) )" ]<li><strong>Distributor:</strong> [types field='project-distributor'][/types]</li>[/wpv-conditional]
    
    

    This will only display the distributor only if the field is NOT empty. So if the field is empty nothing will display. The reference document for this can be seen in the link below .

    https://toolset.com/documentation/legacy-features/views-plugin/checking-fields-and-other-elements-for-emptynon-empty-values/#1-using-the-empty-function

    The above document illustrates how to check for empty custom fields. Please let me know if I was able to provide some form of clarity or if you're still unsure of our conditional shortcode.

    Thanks,
    Shane

    #1968599

    Hi Shane,

    Unfortunately, I am not able to produce a successful result as you are. I did a quick screencap to demonstrate:
    hidden link

    After reviewing your reply, I copied and pasted your shared conditional code snippet to no avail. I was not able to demonstrate conditional functionality across posts (some with completed fields, some with empty fields).

    I have followed all documentation as much as I possibly could. And yet, it still isn't working. I really appreciate any effort applied toward helping us resolve this issue.

    #1968605

    Shane
    Supporter

    Languages: English (English )

    Timezone: America/Jamaica (GMT-05:00)

    Hi Stephen,

    There are multiple ways to check if the field is empty. Another way to check for this is to use the shortcode directly and test.

    [wpv-conditional if="( ' [types field='project-distributor'][/types]' ne '')" ]<li><strong>Distributor:</strong> </li>[/wpv-conditional]
            
    

    I've tested this on the exact same page from your video and it produces the desired result.

    Thanks,
    Shane

    #1968661

    My issue is resolved now. Thank you!