Skip Navigation

[Resolved] How to format conditional output depending on several custom field inputs

This support ticket is created 6 years, 1 month 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.

This topic contains 2 replies, has 2 voices.

Last updated by katrina 6 years, 1 month ago.

Author
Posts
#1137854

Tell us what you are trying to do? Display text depending on custom field inputs

Is there any documentation that you are following? No

Is there a similar example that we can see? No

What is the link to your site? I can provide in a private message

How Can i better format this code so that ONLY the text Matriculated OR Graduated display, depending on custom field inputs, instead of both those words displaying:

[wpv-conditional if="( $(wpcf-is-the-student-currently-matriculated) eq 'M' )"]Matriculated[/wpv-conditional]
[wpv-conditional if="( $(wpcf-is-the-student-currently-matriculated) eq 'M' ) AND ( $(wpcf-ys301-status) eq 'complete' ) AND ( $(wpcf-ys302-status) eq 'complete' ) AND ( $(wpcf-ys303-status) eq 'complete' ) AND ( $(wpcf-ys304-status) eq 'complete' ) AND ( $(wpcf-ys305-status) eq 'complete' )"]Graduated[/wpv-conditional]

I have used the following to acheive my goal, but it's seems like a lot of code. Is this necessary or there is better more succint piece of code I should use?

[wpv-conditional if="( $(wpcf-is-the-student-currently-matriculated) eq 'M' ) AND ( $(wpcf-ys301-status) ne 'complete' ) OR ( $(wpcf-ys302-status) ne 'complete' ) OR ( $(wpcf-ys303-status) ne 'complete' ) OR ( $(wpcf-ys304-status) ne 'complete' ) OR ( $(wpcf-ys305-status) ne 'complete' )"]Matriculated[/wpv-conditional]
[wpv-conditional if="( $(wpcf-is-the-student-currently-matriculated) eq 'M' ) AND ( $(wpcf-ys301-status) eq 'complete' ) AND ( $(wpcf-ys302-status) eq 'complete' ) AND ( $(wpcf-ys303-status) eq 'complete' ) AND ( $(wpcf-ys304-status) eq 'complete' ) AND ( $(wpcf-ys305-status) eq 'complete' )"]Graduated[/wpv-conditional]
#1138131

The documentation on HTML conditions to follow is here:
https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

It is correct that you need to (if required) combine each field you want to listen to into each output you want to condition it with.
So if your output "Graduated" and "Matriculated" should never appear together, and only if a sequence of fields have any given value, then all those need to be combined into 2 conditions applying to each output, since the outputs never should appear together.

You can nest conditions, so for example:
if condition A
if condition B
output
if condition B END
If condition A END

That can allow you to output 2 datasets separately and only if a global set of conditions apply.
This way you can "share" conditions.

Example:

<!-- this is shared by both-->
[wpv-conditional if="( $(wpcf-is-the-student-currently-matriculated) eq 'M' )"]
  //here put the rest of your SINGLE conditions of each output and share in the wrapping conditions the COMMON values.
[/wpv-conditional]
#1138362

Perfect - thanks so much Beda!