Skip Navigation

[Resolved] Zero value for custom field is not displayed on the front-end

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

Problem: I have a custom field that holds scores for a game, values from 0 - 7. When I try to use the value in a conditional or display it on the front-end of the site, the 0 value is shown as empty.

Solution: Use the wpv-post-field shortcode instead of the Types field shortcode to display the zero values correctly.

[wpv-post-field name="wpcf-opponent-score"]

Relevant Documentation:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-post-field

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

Last updated by Christian Cox 6 years, 6 months ago.

Assisted by: Christian Cox.

Author
Posts
#1069354

I am trying to: Create a score (0-7) and display correctly.

Link to a page where the issue can be seen:

I expected to see: The value 0-7

Instead, I got: I received an empty value when I provide a 0, but if I provide a 1-7 it shows correctly. The 0 needs to show as this could be a score in a match. I created a conditional display where if empty it displays 0, but it does not show any other value.

[wpv-conditional if="( empty($(wpcf-opponent-score)) )"]0[/wpv-conditional]

[wpv-conditional if="( NOT(empty($(wpcf-opponent-score))) )"]This field is not empty[/wpv-conditional]
#1069465

Shane
Supporter

Languages: English (English )

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

Hi Eric,

Thank you for contacting our support forum.

This conditional means that you are checking if the field is empty. It will not work if the field is filled out, even if the value is set to 0.

The field must be empty for it to pass the conditional terms.

Please let me know if this helps.

Thanks,
Shane

#1070218

Here is what is happening.

I have a dropdown on a Toolset custom post type which a person can enter the score from 0-7. When the score is 0 it will not display on the view, every other number is able to display. I have not been able to display a 0 without setting a conditional. the conditional to display a 0 seems to be only checking if the field is empty as I have posted in my initial post, but it will not check the second conditional or any other conditional after that in the display.

#1070357
Screen Shot 2018-08-01 at 1.34.47 PM.png

Hi, Shane is on public holiday today so I'll try to help. For the moment, please disregard the conditionals because I think they're over-complicating things. You just want to display the score value, so I would like to see if we can fix the display of the "0". I suspect you are using a Types field shortcode to display the custom field value. Try this instead:

Score: [wpv-post-field name="wpcf-opponent-score"]

I tried this locally to verify and it seems to be working as expected with a zero value in a select custom field. Results below for the screenshot attached.

Sel 1: 0
It's zero

If this isn't working as expected, I'll need to take a closer look.