I have two meta fields in Wordpress (ACF) that track the score of our soccer games. It's a group field with a name of 'score' with two number fields in it, 'bucs' (that's us, the Bucs) and 'opp' for our opponent.
I am able to assign the variables and display them easy enough with:
$score = get_field('score');
$bucsscore = $score['bucs'];
$oppscore = $score['opp'];
echo $bucsscore;
echo $oppscore;
Now my goal is to assign a class to a div based on the game outcome: win, lose, tie. I am trying to get this class by simply comparing the two scores.
What I have so far gives me inconsistent results on every game. Sometimes a 0 - 0 score says we lost. If we win 1 - 0 it says we tie. If we tie 1 - 1 it says we won.
<?php if($bucscore === $oppscore) { echo 'tie-game'; } elseif ($bucscore < $oppscore) { echo 'lost-game'; } elseif ($bucscore > $oppscore) { echo 'won-game'; }?>
I have tested the '===' with '=' and '==' and still get the same inconsistency. I am thinking I can reduce the amount of code if I could create a variable that gave me the class based on the comparison but I am stuck here for now.
In your code, it seems there's a typo in the variable name $bucscore. It should be $bucsscore.
if ($bucsscore === $oppscore) {
echo 'tie-game';
} elseif ($bucsscore < $oppscore) {
echo 'lost-game';
} elseif ($bucsscore > $oppscore) {
echo 'won-game';
}