Skip Navigation

[Resolved] Display content conditionally if a Custom Field has no content

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

Problem:
How can I display something conditionally when a Custom Field has no content? So instead of an empty output, I could output some "placeholder", replacing the empty Custom Field?

Solution:
To display conditionally something depending on fields content (or other type), you can use HTML conditions instead.

Relevant Documentation:

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

This support ticket is created 5 years, 4 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by Joe H. 5 years, 4 months ago.

Assisted by: Beda.

Author
Posts
#1328527

Tell us what you are trying to do?

I am trying to show a "no items found" message if a wpv-for-each loop is empty.

This does not work, but I think shows what I am trying to do. Can you suggest a better way to do this?

I could not find documentation or tickets that speaks to this other than that the wpv-no-items-found is used in Views. I am not using a View in this case:

<ul>
[wpv-for-each field="wpcf-speaker-awards"]
 	<li>[types field="speaker-awards"][/types]</li>
[/wpv-for-each]
</ul>

[wpv-no-items-found]
No items found
[/wpv-no-items-found]
#1328659

wpv-no-items-found will only apply in the case items-found is actually empty, not just one single part of it, but as an entirety.

To display conditionally something depending on fields content (which is what you check using [wpv-for-each field="wpcf-speaker-awards"]), you could use HTML conditions instead.
The basics of this are explained here: https://toolset.com/documentation/user-guides/conditional-html-output-in-views/checking-fields-and-other-elements-for-emptynon-empty-values/

Please let me know if you'd need more particular guidance or information, or in case it doesn't work as expected on your end.

#1329061

My issue is resolved now. Thank you!