• pittdsl

    (@pittdsl)


    Hi Savvas, First thank you for the wonderful plug in, it has solved a display issue for how our soccer league works and has made my life a lot easier. In preparation for the new season, I’ve updated WordPress (7.0.3) and all the plug ins and I’m seeing an issue. Here’s the table:

    And here’s the sorting criteria summary

    Team points is the only Regular order and everything else is Tiebreak order. The two teams in first place didn’t play so the H2H Team points shouldn’t matter.

    I threw Claude at it and it wrote up a bug report…

    Example: Two teams tied on 6 points, 0 games played against each other. Team A has GD +2, Team B has GD +3. Expected order: Team B, then Team A. Actual order: Team A, then Team B — i.e., alphabetical, ignoring GD entirely.

    Root cause:

    In includes/class-sah2h-league-table.php, data() recomputes standings for a tied group by re-querying events scoped only to those specific teams (effectively head-to-head-only). For any Tiebreak Order column, the code is supposed to restore the full-season value when the column is not marked “H2H Only”:

    // ~line 792
    foreach ( $this->h2h_priorities as $temp_priority ) {
        if ( isset( $temp_priority['h2h_only'] ) && '' == $temp_priority['h2h_only'] ) {
            // swap in full-season stat
            foreach ( $team_ids as $temp_team_id ) {
                $merged[ $temp_team_id ][ $temp_priority['column'] ] = $this->temp_merged[ $temp_team_id ][ $temp_priority['column'] ];
            }
        }
    }

    The h2h_only field comes from a plain <input type="checkbox" name="sah2h_tiebreak_order[i][h2h_only]" value="1"> in class-sah2h-tiebreak-criteria.php. When that checkbox is left unchecked (the normal setting for a season-wide fallback stat like GD), standard HTML form behavior means the field isn’t submitted at all — so after saving, sah2h_tiebreak_order has no h2h_only key for that row, rather than an empty string.

    Because of that, isset( $temp_priority['h2h_only'] ) evaluates to false for any unchecked row, the if never runs, and the full-season swap-back never happens. The column then compares using only the (empty, in this case) head-to-head data between the tied teams — every team gets 0, h2h_sort() in the same file sees no difference, and once all configured columns are exhausted it falls back to strcmp() on team name (alphabetical), regardless of the real season-wide GD.

    Suggested fix: treat “key not set” the same as “empty string” when deciding whether to restore full-season data, e.g.:

    if ( '' == sp_array_value( $temp_priority, 'h2h_only', '' ) ) {

    or normalize on save in advanced-h2h-for-sportspress.php so unchecked boxes are stored as h2h_only => '' rather than omitted.

    To reproduce:

    1. Create a Sorting Criteria post with Advanced Sorting.
    2. Set Tiebreak Order: Points (DESC), then Goal Difference (DESC), leaving “H2H Only” unchecked on Goal Difference.
    3. Apply it to a league table where two teams are tied on points but have not played each other, and have different season GD.
    4. Observe the tied teams sort alphabetically instead of by GD.

    I tried to make the change manually, but it doesn’t look to be working. That said I’m not a a PHP/WordPress Dev so maybe I’m missing something. Not to mention Claude gets things wrong…

    Thanks again for the amazing addition to SportsPress and let me know if you need any more information!

    Bob

You must be logged in to reply to this topic.