Skip Navigation

[Resolved] Don’t display a field if it is empty

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

Problem:
How to not display a field (include labels etc.) if it doesn't have a value?

Solution:
You can use use the wpv-conditional shortcode to first test if the field has a value or not before outputting it.

So you would wrap the whole div contents in wpv-conditional shortcodes if you don't want the label to appear either.

Relevant Documentation:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/

100% of people find this useful.

This support ticket is created 6 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.

Our next available supporter will start replying to tickets in about 0.79 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 2 replies, has 2 voices.

Last updated by coetzeeG 6 years, 10 months ago.

Assisted by: Nigel.

Author
Posts
#604973

Hi,

I am using the following type of code to display post fields on a single ad page;

<div class="form-group">
		<label>[wpml-string context='cred-form-Edit product-4714' name='Front derailleur']Front derailleur[/wpml-string]</label><br />
		[types field='front-derailleur'][/types]</div>

You can see an example here: hidden link

Is it possible to hide the field if it has no value?

#605106

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

You can use use the wpv-conditional shortcode to first test if the field has a value or not before outputting it.

So you would wrap the whole div contents in wpv-conditional shortcodes if you don't want the label to appear either.

The technique is described generally here: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

The specific format to check if a custom field is empty is described here: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/

#605169

Dude you rock!

Thanks for pointing me in the right direction, got it working.