Skip Navigation

[Resolved] Setting a conditional display on the output of a calculation through custom code

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 brettB-4 1 year, 5 months ago.

Author
Posts
#2637547

This is a split issue from this original ticket: https://toolset.com/forums/topic/conditional-display-to-eliminate-output-when-fields-are-empty-is-breaking-post/

-------------------------------------------------------------------

The last remaining thing with this I'm realizing now is again on this page:

hidden link

Where the results currently show

TEAM MAKER POINTS
Rome Coca-Cola 21 0
Volley Llamas 12 0

How do I set up a conditional on the Points field as well. That should not display if the output there is 0 points. I'm not sure how to set up the conditional on that because that isn't a single field. That is a calculated total of all the score fields from the Men's, Women's, Mixed A, and Mixed B games. The code for that calculation is as follows:

[wpv-calculate][types field="team-1-score-mens-doubles"][/types]+[types field="team-1-score-womens-doubles"][/types]+[types field="team-1-score-mixed-doubles-1"][/types]+[types field="team-1-score-mixed-doubles-2"][/types] [/wpv-calculate]

So my question is how do I put all that within a conditional? The code for one of the conditionals is as follows:

[wpv-conditional if="( $(wpcf-team-1-score-teammaker) gt 0 )"]

But that one is checking a single field.

Is there any way to have the entirety of the calculation within the conditional? The way I would guess this would be done is as follows:

[wpv-conditional if="( $([wpv-calculate][types field="team-1-score-mens-doubles"][/types]+[types field="team-1-score-womens-doubles"][/types]+[types field="team-1-score-mixed-doubles-1"][/types]+[types field="team-1-score-mixed-doubles-2"][/types] [/wpv-calculate]) gt 0 )"]

But I'd also guess that won't work. I tried this and it did work to eliminate the display of the Points column on this match, but it also eliminated it on all the other matches even when the calculation did have results over zero.

Is there a way to eliminate the Points column when the calculated amount is zero? When the matches consist of the TeamMaker game only, that is the only thing that should display. The Points column is irrelevant in those matches. But the Points column is vital to all other matches.

#2638373

Nigel
Supporter

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

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

Hi there

Minesh is on vacation so is unable to continue with this.

I'm not familiar with your site, but from reading this question it seems like it would be sufficient to check if any of the fields being used in the calculation are not zero, rather than having to perform the calculation and test its result. (Unless teams can get negative scores that cancel each other out.)

So your condition would be if team-1-score-mens-doubles != 0 OR team-1-score-womens-doubles != 0 OR team-1-score-mixed-doubles-1 != 0 OR team-1-score-mixed-doubles-2 != 0.

Does that make sense?

#2638385

Perfect! Thanks for the logic lesson on this one. I'm not sure why I didn't think of that because I used the same approach to eliminate headers that were unneeded, basing it on a greater than zero score for the first field. I didn't think about the first field being zero would mean that the whole calculation field wouldn't be included, but you're right on that. If that field is zero, then all the fields included in the calculation will be zero as well, at least with how this tournament was structured.

The only time this won't work is if we have a match with a structure where the first field is not used, but the 2nd, 3rd, and/or 4th field are used. I don't think we will have that though. But I'll have to remember that possibility, so I'm adding it to this ticket in case I have to refer back to this in the future to remember this detail, as well as to tell you that one possible logic flaw for this. But what you suggested works perfectly for the way this current tournament is structured.

We're gradually expanding the functionality of all of this to allow for very different tournament and match structures. That means A LOT of conditionals are needed with the setup. Every time another tournament is completed, it is likely that I'll have more that needs to be changed. It will gradually get refined to handle everything possibly needed.

#2638387

All good. Thanks as always.