Conditional Equations
Conditional equations let you include comparison logic in league table column and player statistic formulas. Instead of a pure arithmetic expression, you can write a formula where a sub-expression evaluates to 1 (true) or 0 (false) based on a comparison, and then multiply that result into a larger calculation.
This feature is provided by the Conditional Equations module, which is bundled with the core SportsPress plugin at includes/sportspress/modules/sportspress-conditional-equations.php.
Comparison Operators
When the Conditional Equations module is active, the following operators are added to the equation builder palette under Operators:
Button | Meaning |
| Greater than |
| Less than |
| Equal to |
| Not equal to |
| Greater than or equal to |
| Less than or equal to |
These operators are available in the equation builder for Table Columns and Player Statistics.
How Evaluation Works
A conditional sub-expression in parentheses evaluates to either 1 (the condition is true) or 0 (the condition is false).
The general pattern is:
( left_operand operator right_operand ) * value_if_true
Because a true condition returns 1 and a false condition returns 0, multiplying by the condition acts as an if/then gate: the value is included when the condition is true and zeroed out when it is false.
To express an if/then/else structure, combine two conditional expressions:
( condition ) * value_if_true + ( negated_condition ) * value_if_false
Or more simply, since the two branches are mutually exclusive:
( condition ) * value_if_true + ( 1 - ( condition ) ) * value_if_false
Examples
Cap a value at a maximum
To give at most 3 points for a win but cap it so goal difference over 10 does not add extra:
$win * 3 + ( ($goalsfor - $goalsagainst) > 10 ) * 0
A simpler cap example — limit goal difference to a maximum of 10:
( ($goalsfor - $goalsagainst) > 10 ) * 10 + ( ($goalsfor - $goalsagainst) <= 10 ) * ($goalsfor - $goalsagainst)
When $goalsfor - $goalsagainst is greater than 10, the first branch returns 10. When it is 10 or less, the second branch returns the actual difference.
Handicap scoring
To add a bonus point when goals for exceed goals against by more than 2:
$win * 3 + ( ($goalsfor - $goalsagainst) > 2 ) * 1
The ( ($goalsfor - $goalsagainst) > 2 ) sub-expression evaluates to 1 when the condition is met and 0 otherwise. Multiplying by 1 adds a bonus point only in that case.
Zero out a value conditionally
To show goal difference only when positive (otherwise show 0):
( ($goalsfor - $goalsagainst) > 0 ) * ($goalsfor - $goalsagainst)
Nested Conditions
Conditions can be nested inside larger expressions. The equation engine evaluates innermost parentheses first. You can wrap a conditional expression in outer parentheses and combine it with other operators.
For example:
( ( $goalsfor > $goalsagainst ) * 3 ) + ( ( $goalsfor == $goalsagainst ) * 1 )
This awards 3 points if goals for exceed goals against, 1 point if equal, and 0 otherwise.
When to Use Conditional Equations vs Regular Equations
Use a regular arithmetic equation when the calculation is always the same formula regardless of values — for example, $win * 3 + $draw * 1.
Use a conditional equation when the result depends on which range a value falls in, when you need to cap or floor a value, or when you want to include a bonus or penalty that only applies under certain conditions.
Do not use conditional equations for simple win/loss/draw point assignments. The standard approach is to use $win * 3 + $draw * 1 without conditions. Reserve conditional expressions for cases where the point value or displayed value changes based on the magnitude of a result.
Building Conditional Equations in the Builder
Open the edit screen for a Table Column or Player Statistic.
In the Equation meta box, use the Operators row in the palette to click
(to open a parenthesis group.Add the left operand variable (for example, click a Result token like Goals for).
Click the
-operator and another variable to form a difference.Click the comparison operator (for example
>for greater than).Click a constant (for example
10).Click
)to close the parenthesis group.Click
*and then the value to multiply by when the condition is true.Add
+and the fallback expression for the false case if needed.Click Publish or Update to save.
The stored equation is a space-separated string such as ( $goalsfor - $goalsagainst > 10 ) * 10. You can inspect or edit this string directly if needed by reading the sp_equation post meta value.
