Skip Navigation

[Resolved] A way to loop through and display field name and value if a value exists

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

Problem:

Checking fields and other elements for Empty/Non-empty Values

Solution:

You can follow our document to setup the wpv-conditional shortcodes, check the custom field value isn't empty, then display the result:

Relevant Documentation:

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

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

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 5 replies, has 2 voices.

Last updated by willB 3 years ago.

Assisted by: Luo Yang.

Author
Posts
#2257813

Tell us what you are trying to do?

I have a CPT with 80-100 Feilds for users to fill out if they apply to them. Most users will only fill out 2-5 of them. Rather than creating a view with a ton of conditionals - is there a way to loop through and simply display a Feild name and its value if the field has a value?

Just trying to create a simple unstyled printout type page.

#2258055

Hello,

You can follow our document to setup the wpv-conditional shortcodes, check the custom field value isn't empty, then display the result:
https://toolset.com/documentation/legacy-features/views-plugin/checking-fields-and-other-elements-for-emptynon-empty-values/

#2258417

Luo, thank you for the response. 100% understood on the conditional shortcodes from the legacy toolset types. That was my thinking at first and I would just create 80-100 conditional statements (one for each field).

The question here is if there is a way to create a loop that checks each field for a view if it has a value and display if it does. Would save time on writing 80-100 conditionals (one for each field to check if there is a value) but also would give some flexibility in the future for when we add in additional fields in the CPT so we would not have to go back and create more conditionals within the view.

An example would be a feature like a contact form builder where you have the option to insert a value like {all fields} for all answers that were filled out with a value into an email body.

My thought would be something like:

[wpv-items-found]
<wpv-loop>
[wpv-conditional if="( '[***Generic call for Field***][/types]' ne '' )"]
<p> ***Generic call for Field Title*** ***Field Value***</p>
[/wpv-conditional]
</wpv-loop>
[/wpv-items-found]

Possible within Toolset? Really the question would be if there is a way to check each field made within Custom Fields for a Post Type in a loop for a value - if yes then display.

Let me know your thoughts.

#2258825

Unfortunately, there isn't such kind of built-in feature within Toolset plugins, you need to setup the shortcode [wpv-conditional] one by one for each custom field.

#2259209

Thank you Lou - Would be a great feature to have, might tackle with some custom code in an array at some point in the future but for now I will stick with the legacy conditionals.

#2259213

My issue is resolved now. Thank you!