Home › Toolset Professional Support › [Resolved] Conditional display to eliminate output when fields are empty is breaking post.
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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
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/Karachi (GMT+05:00)
Related documentation:
This topic contains 18 replies, has 3 voices.
Last updated by Waqar 1 year, 3 months ago.
Assisted by: Waqar.
We now have our Matches content set to display five different games within each match. We have Men's Doubles, Women's Doubles, Mixed Doubles A, Mixed Doubles B, and a new game called TeamMaker which is a tiebreaker game. But we expect to have other tournaments with different Match structures where we might just have Men's Doubles, Women's Doubles, and Mixed Doubles A (for example). In our Match output, I am trying to set up each game display to be conditional based on if the score fields are empty. An example of how the score field will display is as follows:
[wpv-conditional if="( $(wpcf-team-1-score-mens-doubles) ne '' )"]<div style="width: 75px; display: inline-block; text-align: right; border: 1px solid #ffffff; padding: 7px;"> [wpv-conditional if="( $(wpcf-team-1-result-mens-doubles) eq 'Win' )"]<font style="color: #02fd14;">[types field='team-1-score-mens-doubles' output='raw'][/types]</font>[/wpv-conditional] [wpv-conditional if="( $(wpcf-team-1-result-mens-doubles) eq 'Loss' )"]<font style="color: #ffffff;">[types field='team-1-score-mens-doubles' output='raw'][/types]</font>[/wpv-conditional] </div>[/wpv-conditional]
This code first checks if teh score field isn't empty. If it empty, then nothing at all should display. If it isn't empty, then there is another conditional check where the winning score will display in green and the losing score will display in white.
So if I leave the score fields empty for any game, that game shouldn't display at all. I have the headers also set to conditionally display based on the same first score field.
The match I'd like you to look at is here:
hidden link
On this Match, when I empty the Men's score fields, the Men's game does not appear, as expected.
But when I empty the Women's score fields, or either of the MIxed Doubles fields, the whole display of the match breaks and shows a white screen where the match template should be displaying. If I then enter 0 as the two scores of each of these, then the display is no longer broken, but the games display where we don't want them to.
I can't understand why the Men's game is working like it should but trying to do the same thing on Women's, MIxed A, or Mixed B breaks the display.
On this specific match, the ONLY game that should be displaying at all is the TeamMaker game.
Any ideas why this is happening? I'm assuming I've done something wrong with all the conditionals I've set up, but I can't figure it out.
Hello. Thank you for contacting the Toolset support.
I will require admin access details in order to know whats going wrong with your setup.
Can you please send me admin access details as well as tell me what is your expected output.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
I'm on the following page: hidden link
I can see empty cells with the table gets displayed. Can you please share details about what is your expected output and what content you want to display and what content you want to hide?
The desired output on this page is as follows:
TEAM MAKER POINTS
Rome Coca-Cola 21 0
Volley Llamas 12 0
I'm trying to make the WOMEN, MIXED A, MIXED B behave the same way the MEN one is. I thought I set up the conditional code the same way for each one, but having empty fields with Women, Mixed A and/or Mixed B causes the view to white screen. Note that Men is empty and that's working as it should by not displaying that column at all. I can't figure out the difference here.
Can you please check now: hidden link
I've adjusted the conditional as given under you added to your following content template:
=> hidden link
<div style="width: 250px; display: inline-block; border: 0px solid #ffffff; padding: 7px;"><strong></strong></div> [wpv-conditional if="( $(wpcf-team-1-score-mens-doubles) ne '' ) " ]<div style="width: 75px; display: inline-block; text-align: center; background: #ffffff; color: #000000; font-weight: bold; padding: 7px;">MEN</div>[/wpv-conditional] [wpv-conditional if="( $(wpcf-team-1-score-womens-doubles) ne '') AND ( $(wpcf-team-1-score-womens-doubles) gt 0 ) "]<div style="width: 75px; display: inline-block; text-align: center; background: #ffffff; color: #000000; font-weight: bold; padding: 7px;">WOMEN</div>[/wpv-conditional] [wpv-conditional if="( $(wpcf-team-1-score-mixed-doubles-1) ne '' ) AND ( $(wpcf-team-1-score-mixed-doubles-1) gt 0 )"]<div style="width: 75px; display: inline-block; text-align: center; background: #ffffff; color: #000000; font-weight: bold; padding: 7px;">MIXED A</div>[/wpv-conditional] [wpv-conditional if="( $(wpcf-team-1-score-mixed-doubles-2) ne '' ) AND ( $(wpcf-team-1-score-mixed-doubles-2) gt 0 )"]<div style="width: 75px; display: inline-block; text-align: center; background: #ffffff; color: #000000; font-weight: bold; padding: 7px;">MIXED B</div>[/wpv-conditional] [wpv-conditional if="( $(wpcf-team-1-score-teammaker) ne '' )"]<div style="width: 75px; display: inline-block; text-align: center; background: #ffffff; color: #000000; font-weight: bold; padding: 7px;">TEAM MAKER</div>[/wpv-conditional] <div style="width: 75px; display: inline-block; text-align: center; background: #02fd14; color: #000000; font-weight: bold; padding: 7px; margin-left: 5px;">POINTS</div><br> <div style="width: 250px; display: inline-block; border: 1px solid #ffffff; padding: 7px;"><strong><a href="[wpv-post-url item="@team-1-match.parent"]">[types field='team-name' item='@team-1-match.parent'][/types]</a></strong></div> [wpv-conditional if="( $(wpcf-team-1-score-mens-doubles) ne '' )"]<div style="width: 75px; display: inline-block; text-align: right; border: 1px solid #ffffff; padding: 7px;"> [wpv-conditional if="( $(wpcf-team-1-result-mens-doubles) eq 'Win' )"]<font style="color: #02fd14;">[types field='team-1-score-mens-doubles' output='raw'][/types]</font>[/wpv-conditional] [wpv-conditional if="( $(wpcf-team-1-result-mens-doubles) eq 'Loss' )"]<font style="color: #ffffff;">[types field='team-1-score-mens-doubles' output='raw'][/types]</font>[/wpv-conditional] </div>[/wpv-conditional] [wpv-conditional if="( $(wpcf-team-1-score-womens-doubles) ne '' ) AND ( $(wpcf-team-1-score-womens-doubles) gt 0 )"]<div style="width: 75px; display: inline-block; text-align: right; border: 1px solid #ffffff; padding: 7px;"> [wpv-conditional if="( $(wpcf-team-1-result-womens-doubles) eq 'Win' )"]<font style="color: #02fd14;">[types field='team-1-score-womens-doubles' output='raw'][/types]</font>[/wpv-conditional] [wpv-conditional if="( $(wpcf-team-1-result-womens-doubles) eq 'Loss' )"]<font style="color: #ffffff;">[types field='team-1-score-womens-doubles' output='raw'][/types]</font>[/wpv-conditional] </div>[/wpv-conditional] [wpv-conditional if="( $(wpcf-team-1-score-mixed-doubles-1) ne '' ) AND ( $(wpcf-team-1-score-mixed-doubles-1) gt 0 )"]<div style="width: 75px; display: inline-block; text-align: right; border: 1px solid #ffffff; padding: 7px;"> [wpv-conditional if="( $(wpcf-team-1-result-mixed-doubles-a) eq 'Win' )"]<font style="color: #02fd14;">[types field='team-1-score-mixed-doubles-1' output='raw'][/types]</font>[/wpv-conditional] [wpv-conditional if="( $(wpcf-team-1-result-mixed-doubles-a) eq 'Loss' )"]<font style="color: #ffffff;">[types field='team-1-score-mixed-doubles-1' output='raw'][/types]</font>[/wpv-conditional] </div>[/wpv-conditional] [wpv-conditional if="( $(wpcf-team-1-score-mixed-doubles-2) ne '' ) AND ( $(wpcf-team-1-score-mixed-doubles-2) gt 0 )"]<div style="width: 75px; display: inline-block; text-align: right; border: 1px solid #ffffff; padding: 7px;"> [wpv-conditional if="( $(wpcf-team-1-result-mixed-doubles-b) eq 'Win' )"]<font style="color: #02fd14;">[types field='team-1-score-mixed-doubles-2' output='raw'][/types]</font>[/wpv-conditional] [wpv-conditional if="( $(wpcf-team-1-result-mixed-doubles-b) eq 'Loss' )"]<font style="color: #ffffff;">[types field='team-1-score-mixed-doubles-2' output='raw'][/types]</font>[/wpv-conditional] </div>[/wpv-conditional] [wpv-conditional if="( $(wpcf-team-1-score-teammaker) ne '' )"]<div style="width: 75px; display: inline-block; text-align: right; border: 1px solid #ffffff; padding: 7px;"> [wpv-conditional if="( $(wpcf-team-1-result-teammaker) eq 'Win' )"]<font style="color: #02fd14;">[types field='team-1-score-teammaker' output='raw'][/types]</font>[/wpv-conditional] [wpv-conditional if="( $(wpcf-team-1-result-teammaker) eq 'Loss' )"]<font style="color: #ffffff;">[types field='team-1-score-teammaker' output='raw'][/types]</font>[/wpv-conditional] </div>[/wpv-conditional] <div style="width: 75px; display: inline-block; text-align: right; border: 1px solid #ffffff; padding: 7px; margin-left: 5px;"> [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] </div><br> <div style="width: 250px; display: inline-block; border: 1px solid #ffffff; padding: 7px;"><strong><a href="[wpv-post-url item="@team-2-match.parent"]">[types field='team-name' item='@team-2-match.parent'][/types] </a></strong></div> [wpv-conditional if="( $(wpcf-team-2-score-mens-doubles) ne '' )"]<div style="width: 75px; display: inline-block; text-align: right; border: 1px solid #ffffff; padding: 7px;"> [wpv-conditional if="( $(wpcf-team-2-result-mens-doubles) eq 'Win' )"]<font style="color: #02fd14;">[types field='team-2-score-mens-doubles' output='raw'][/types]</font>[/wpv-conditional] [wpv-conditional if="( $(wpcf-team-2-result-mens-doubles) eq 'Loss' )"]<font style="color: #ffffff;">[types field='team-2-score-mens-doubles' output='raw'][/types]</font>[/wpv-conditional] </div>[/wpv-conditional] [wpv-conditional if="( $(wpcf-team-2-score-womens-doubles) ne '' ) AND ( $(wpcf-team-2-score-womens-doubles) gt 0 )"]<div style="width: 75px; display: inline-block; text-align: right; border: 1px solid #ffffff; padding: 7px;"> [wpv-conditional if="( $(wpcf-team-2-result-womens-doubles) eq 'Win' )"]<font style="color: #02fd14;">[types field='team-2-score-womens-doubles' output='raw'][/types]</font>[/wpv-conditional] [wpv-conditional if="( $(wpcf-team-2-result-womens-doubles) eq 'Loss' )"]<font style="color: #ffffff;">[types field='team-2-score-womens-doubles' output='raw'][/types]</font>[/wpv-conditional] </div>[/wpv-conditional] [wpv-conditional if="( $(wpcf-team-2-score-mixed-doubles-1) ne '' ) AND ( $(wpcf-team-2-score-mixed-doubles-1) gt 0 )"]<div style="width: 75px; display: inline-block; text-align: right; border: 1px solid #ffffff; padding: 7px;"> [wpv-conditional if="( $(wpcf-team-2-result-mixed-doubles-a) eq 'Win' )"]<font style="color: #02fd14;">[types field='team-2-score-mixed-doubles-1' output='raw'][/types]</font>[/wpv-conditional] [wpv-conditional if="( $(wpcf-team-2-result-mixed-doubles-a) eq 'Loss' )"]<font style="color: #ffffff;">[types field='team-2-score-mixed-doubles-1' output='raw'][/types]</font>[/wpv-conditional] </div>[/wpv-conditional] [wpv-conditional if="( $(wpcf-team-2-score-mixed-doubles-2) ne '' ) AND ( $(wpcf-team-2-score-mixed-doubles-2) gt 0 )"]<div style="width: 75px; display: inline-block; text-align: right; border: 1px solid #ffffff; padding: 7px;"> [wpv-conditional if="( $(wpcf-team-2-result-mixed-doubles-b) eq 'Win' )"]<font style="color: #02fd14;">[types field='team-2-score-mixed-doubles-2' output='raw'][/types]</font>[/wpv-conditional] [wpv-conditional if="( $(wpcf-team-2-result-mixed-doubles-b) eq 'Loss' )"]<font style="color: #ffffff;">[types field='team-2-score-mixed-doubles-2' output='raw'][/types]</font>[/wpv-conditional] </div>[/wpv-conditional] [wpv-conditional if="( $(wpcf-team-2-score-teammaker) ne '' )"]<div style="width: 75px; display: inline-block; text-align: right; border: 1px solid #ffffff; padding: 7px;"> [wpv-conditional if="( $(wpcf-team-2-result-teammaker) eq 'Win' )"]<font style="color: #02fd14;">[types field='team-2-score-teammaker' output='raw'][/types]</font>[/wpv-conditional] [wpv-conditional if="( $(wpcf-team-2-result-teammaker) eq 'Loss' )"]<font style="color: #ffffff;">[types field='team-2-score-teammaker' output='raw'][/types]</font>[/wpv-conditional] </div>[/wpv-conditional] <div style="width: 75px; display: inline-block; text-align: right; border: 1px solid #ffffff; padding: 7px; margin-left: 5px;"> [wpv-calculate][types field="team-2-score-mens-doubles"][/types]+[types field="team-2-score-womens-doubles"][/types]+[types field="team-2-score-mixed-doubles-1"][/types]+[types field="team-2-score-mixed-doubles-2"][/types] [/wpv-calculate] </div><br><br> [toolset_access role="Administrator" operator="allow" raw="true"] [toolset-edit-post-link content_template_slug='edit-match-template' target='self']Edit[/toolset-edit-post-link]<br><br> [/toolset_access]
you have added the 0 (zero) to your comparison fields of custom fields "team-2-score-womens-doubles", "team-2-score-mixed-doubles-2" and "team-2-score-mixed-doubles-1" and you have added condition to check for not empty and field contains the 0 (zero) value so that is why condition was not satisfied as zero value is not the empty value.
As you can see with above code I've adjusted the condition with "AND" clause to check for zero value for instance:
[wpv-conditional if="( $(wpcf-team-2-score-womens-doubles) ne '' ) AND ( $(wpcf-team-2-score-womens-doubles) gt 0 )"]
Can you please confirm it works as expected now.
Well, it is displaying correctly right now, but the only reason I had those zero scores in there was because the view was a white screen if they were empty. We don't want to have those zero scores in there. I only added them to get the page to display at all.
With the template as you have it now, the match I was having you look at is displaying correctly, but now there are other Playoff Round matches that are more problematic than before. I can't explain why that is happening either. On this page:
hidden link
It is displaying as follows:
Professional Poachers vs. Sweet Relish
TEAM MAKER POINTS
Professional Poachers 22 0
Sweet Relish 20 0
There is an extra empty column under Team Maker that is causing the score from that to appear under Points instead and then the 0 points are displaying outside the headers.
So something is still wrong and I'm even more baffled than before on this one. I don't know why the one you were on is fine now and this other one is not.
Well, I went through everything and decided to put the template back the way I had it and I tried changing EVERY instance of
ne ''
to
gt 0
instead in there and that worked. Everything is displaying as it should on this now, though I can't really explain why ne'' was breaking things with Women's, Mixed A, and Mixed B.
I wish I could understand why the way I had it before caused the white screen result, but since it is working now I won't ask you to take any more of your time to solve that for me.
There is now one more thing with this that I'm seeing I need to ask. If you need to split this to another ticket, that's OK. I'll go ahead and add it as a separate post here so if you split it, none of this discussion will be present.
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.
I do not see anything on this page: hidden link
It shows white page.
Unreal. It was working fine the last time I looked at it. I am losing my mind with this. The last thing I did was to remove the failed effort with that conditional that I tried on the calculation field. Now it is broken everywhere I use this, not just on the content template. I have two views where I was using this same thing.
Can you determine why this white screen is happening. My guess is whatever is happening now is happening for the same reason it was happening before.
I've now tried to put everything back totally to how I originally had it and everything is still white screening now. I had the original code saved off site. I've pasted it all back the way I had it before and now everything is still broken.
Whatever is causing the white screen to happen now is likely still the reason for my original reason for filing this ticket.
Oh yeah, I also removed the 0 scores. But when I did that I checked if it still worked and I thought it did previously. Maybe I didn't check it. I thought I did.
When I add the 0 scores back in on this page:
hidden link
It works again. So there is something about the scores being left blank that is breaking things with my conditionals.
Now I'm seeing that it is working again on all pages where the views were as well, just from me changing the empty score fields to 0 on that one match. Bizarre.
OK, I have the white screens gone again now. I have confirmed on the match we're looking at that if I remove the 0 scores so the score fields are blank, the white screen comes back. So if you can determine why that is happening, that would help because we definitely don't want to have to fill in zeros on every match we create to avoid the white screen. When the matches are originally created, it is before the matches are played, so all matches will have empty score fields initially. Then we fill in the scores as the matches are played. If the white screen situation remains, then we won't be able to fill in results that will display in real time unless we prepopulate all score fields with zeros. So if you can figure out why having empty score fields is causing the white screen when these conditionals are added, I think that's the solution to the biggest problem.
Regardless, now that the white screens are gone, you can see if there's a way to conditionally eliminate that Total Points column if the total there is zero.
Note that I tried changing all of these to the way you did it
( $(wpcf-team-1-score-mixed-doubles-1) ne '' ) AND ( $(wpcf-team-1-score-mixed-doubles-1) gt 0 )
And that didn't solve the white screen thing either. Only populating the score fields with 0 works. And note that I can leave the Men's score field empty and that doesn't cause the white screen. Only the Women's, MIxed A and MIxed B score fields are causing this. I am utterly baffled by what it is doing.
Right now I have it back to using only
( $(wpcf-team-1-score-mens-doubles) gt 0 )
Note also that this white screen issue did not happen with score fields empty until I started adding these conditionals. When the conditionals are removed, the empty score fields do not cause problems and display fine.
Ok so do you need further assistance with this? if so, you are welcome to create new ticket.
Yeah, but this is still part of the original ticket. I'm just now seeing that solving why the white screen thing is happening is now essential.
Stopping the display of the Total Points column when that is zero is a separate matter. I'll just go ahead and set that up as a separate ticket myself now.
But can you determine why emptying the score fields with my conditionals present is causing the white screen? The steps I'd like you to take to see exactly what I'm talking about there are as follows:
1) Go to this match page: hidden link
2) Click edit to bring up the edit match form.
3) Change the Men's scores to empty instead of zero and submit the form. The match still displays as it should.
4) Click edit to bring up the edit match form again.
5) Change the Women's scores to empty instead of zero and submit the form. The match now has the white screen.
6) Hit your back button to get back to the match form.
7) Change the Women's scores back to zero and submit the form. The white screen problem is solved.
I'm finding this completely bizarre and can't figure out what is causing it. Initially I said as long as it works, I won't worry about having you figure this out. But now I'm seeing that it is going to force us to pre-populate every match score field to zero to avoid the white screen. That's not good.
But we don't want to have to pre-populate all these score fields with zeros for every match. When we initially set up the matches there are no scores because the matches haven't been played yet. It adds time to match creation to have to enter zeros for every score field. It is only after I added these conditionals that the white screen problem started.
The reason I'm setting it up this way now is the client has had me add the ability to have matches where only the TeamMaker game is played, not the Men's, Women's, Mixed A, and Mixed B. So all the conditionals are my way of making the system flexible enough to handle every match structure. He has also said he'd like the ability to have Men's, Women's, and only one Mixed game too. So I'm going to have to figure that out later as well. But these conditionals will make it to where any game that isn't used won't be displayed.
Actually, now I'm realizing that I can set the default value of all score fields to be zero and we won't have to pre-populate them all every time we create the matches. That's another solution that would be fine. But can you still take a quick peek at the 7 steps above to see if something quick and obvious jumps out to you as the reason for the white screen? I'm just so confused why the men's score fields are fine and the others break it.
I've set up the other issue with the calculation field as a separate ticket here: https://toolset.com/forums/topic/setting-a-conditional-display-on-the-output-of-a-calculation-through-custom-code/