Title: granedoy's Replies | WordPress.org

---

# granedoy

  [  ](https://wordpress.org/support/users/granedoy/)

 *   [Profile](https://wordpress.org/support/users/granedoy/)
 *   [Topics Started](https://wordpress.org/support/users/granedoy/topics/)
 *   [Replies Created](https://wordpress.org/support/users/granedoy/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/granedoy/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/granedoy/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/granedoy/engagements/)
 *   [Favorites](https://wordpress.org/support/users/granedoy/favorites/)

 Search replies:

## Forum Replies Created

Viewing 9 replies - 1 through 9 (of 9 total)

 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[SportsPress - Sports Club & League Manager] Mid-Season Transfers incorrectly assigning previous games to new team](https://wordpress.org/support/topic/mid-season-transfers-incorrectly-assigning-previous-games-to-new-team/)
 *  Thread Starter [granedoy](https://wordpress.org/support/users/granedoy/)
 * (@granedoy)
 * [3 months, 1 week ago](https://wordpress.org/support/topic/mid-season-transfers-incorrectly-assigning-previous-games-to-new-team/#post-18903230)
 * **[BUG FIX] Midseason Transfers counting games from wrong team**
 * Hi everyone,
 * I want to share a bug I found in SportsPress Pro 2.7.26/2.7.29 related to the
   Midseason Transfers module, and the fix I applied in case anyone else runs into
   the same issue.
 * **The Problem**
 * When a player is transferred mid-season, their statistics table incorrectly includes
   games played _before_ the transfer date as games for the _new_ team.
 * Example: A player played 2 games for Team A, then transferred to Team B on May
   6. After the transfer, the stats table showed 2 games for Team B instead of 1.
 * All the data was correct (event dates, transfer date, boxscores), but the filtering
   was broken.
 * **Root Cause**
 * The bug is in this file:
   `wp-content/plugins/sportspress-pro/includes/sportspress-
   midseason-transfers/sportspress-midseason-transfers.php`
 * In the `event_args()` function, when a team is selected (`$selected_team != -
   1`), the function returns immediately after adding the team filter — **without
   applying the `date_from` filter**. This means all games where the player appeared
   for that team are counted, regardless of the transfer date.
 * Additionally, there is a typo in the `$date_from && $date_to` block where `$date_from`
   is used twice instead of `$date_from` and `$date_to`.
 * **The Fix**
 * Replace the entire `event_args()` function with the following:
 *     ```wp-block-code
       public function event_args( $args = array(), $data = array(), $season_id = 0, $selected_team = -1 ) {
           // Check if a team is selected and add it to the args.
           if ( -1 != $selected_team && ( 'sp_team' === get_post_type( $selected_team ) ) ) :
               $args['meta_query'][] = array(
                   'key'     => 'sp_team',
                   'value'   => array( $selected_team ),
                   'compare' => 'IN',
               );
   
               // Only apply date filter for mid-season transfer rows (non-integer season_id)
               if ( (int) $season_id != $season_id ) {
                   $date_from = false;
                   foreach ( $data as $index => $season_data ) {
                       if ( (int) floor( $index ) != (int) $season_id ) {
                           continue;
                       }
                       $df = sp_array_value( $season_data, 'date_from', false );
                       if ( $df ) {
                           $date_from = $df;
                           break;
                       }
                   }
                   if ( $date_from ) {
                       $args['date_query'] = array(
                           array(
                               'after'     => $date_from,
                               'inclusive' => true,
                           )
                       );
                   }
               }
   
               return $args;
           endif;
   
           // Limit data to same season
           foreach ( $data as $index => $season_data ) {
               if ( (int) $index == (int) $season_id ) continue;
               unset( $data[ $index ] );
           }
   
           // Sort the data by date
           uasort( $data, array( $this, 'sort_by_date' ) );
   
           // Move the internal pointer to the currently selected season
           while ( key( $data ) != $season_id ) next( $data );
   
           // Check if there is a data_from value and assign it to $date_from variable
           $date_from = sp_array_value( current( $data ), 'date_from', false );
   
           // Move pointer to next season
           next( $data );
   
           // Check if there is a following entry of same season and assign the date_from to $date_to variable
           $date_to = sp_array_value( current( $data ), 'date_from', false );
   
           if ( $date_from && $date_to ):
               $args['date_query'] = array(
                   array(
                       'after'     => $date_from,
                       'before'    => $date_to,
                       'inclusive' => true,
                   )
               );
           elseif ( $date_from ):
               $args['date_query'] = array(
                   array(
                       'after'     => $date_from,
                       'inclusive' => true,
                   )
               );
           elseif ( $date_to ):
               $args['date_query'] = array(
                   array(
                       'before'    => $date_to,
                       'inclusive' => false,
                   )
               );
           endif;
   
           return $args;
       }
       ```
   
 * **Tested on:** SportsPress Pro 2.7.29, WordPress 6.8.1, baseball/softball configuration
   with mid-season transfers enabled.
 * Hope this helps someone. Would be great if ThemeBoy could include this fix in
   the next release!
 * — Reported and fixed by a community member.
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[SportsPress - Sports Club & League Manager] Missing Divisions & Stats](https://wordpress.org/support/topic/missing-divisions-stats/)
 *  [granedoy](https://wordpress.org/support/users/granedoy/)
 * (@granedoy)
 * [1 year, 10 months ago](https://wordpress.org/support/topic/missing-divisions-stats/#post-18048349)
 * I think I can help you but I have to see something in the administrator to be
   correct. Are you willing to create a temporary user?
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[SportsPress - Sports Club & League Manager] semi-finals of 2 teams and one in the final waiting for the winner](https://wordpress.org/support/topic/semi-finals-of-2-teams-and-one-in-the-final-waiting-for-the-winner/)
 *  Thread Starter [granedoy](https://wordpress.org/support/users/granedoy/)
 * (@granedoy)
 * [1 year, 11 months ago](https://wordpress.org/support/topic/semi-finals-of-2-teams-and-one-in-the-final-waiting-for-the-winner/#post-17991989)
 * Thank you all for your responses. I decided to create a new league and put semi-
   final in the title. I then had to add each player to that new league for the 
   stats to display.
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[SportsPress - Sports Club & League Manager] Problema con Tablas de Ligas y Torneos (fase playoffs)](https://wordpress.org/support/topic/problema-con-tablas-de-ligas-y-torneos-fase-playoffs/)
 *  [granedoy](https://wordpress.org/support/users/granedoy/)
 * (@granedoy)
 * [2 years, 3 months ago](https://wordpress.org/support/topic/problema-con-tablas-de-ligas-y-torneos-fase-playoffs/#post-17747261)
 * O también puedes crear otra season con el mismo nombre y agregandole que es un
   playoff y como quien dice todo estará desde 0
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[SportsPress - Sports Club & League Manager] Problema con Tablas de Ligas y Torneos (fase playoffs)](https://wordpress.org/support/topic/problema-con-tablas-de-ligas-y-torneos-fase-playoffs/)
 *  [granedoy](https://wordpress.org/support/users/granedoy/)
 * (@granedoy)
 * [2 years, 3 months ago](https://wordpress.org/support/topic/problema-con-tablas-de-ligas-y-torneos-fase-playoffs/#post-17747259)
 * Se me ocurre que hagas una tabla de manera manual con solo los datos de la serie
   regular.
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[SportsPress - Sports Club & League Manager] Player List not sortingf correctly](https://wordpress.org/support/topic/player-list-not-sortingf-correctly/)
 *  [granedoy](https://wordpress.org/support/users/granedoy/)
 * (@granedoy)
 * [2 years, 4 months ago](https://wordpress.org/support/topic/player-list-not-sortingf-correctly/#post-17517855)
 * Glad you were able to solve it.
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[SportsPress - Sports Club & League Manager] collective statistics per team](https://wordpress.org/support/topic/collective-statistics-per-team/)
 *  Thread Starter [granedoy](https://wordpress.org/support/users/granedoy/)
 * (@granedoy)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/collective-statistics-per-team/#post-17512356)
 * but that’s the standings. I am referring to the collective statistics per team.
   The plugin already does the individual ones but I am referring to the sum of 
   everything per team
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[SportsPress - Sports Club & League Manager] collective statistics per team](https://wordpress.org/support/topic/collective-statistics-per-team/)
 *  Thread Starter [granedoy](https://wordpress.org/support/users/granedoy/)
 * (@granedoy)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/collective-statistics-per-team/#post-17512310)
 * No, how could I do it? Could you be more specific?
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[SportsPress - Sports Club & League Manager] Player List not sortingf correctly](https://wordpress.org/support/topic/player-list-not-sortingf-correctly/)
 *  [granedoy](https://wordpress.org/support/users/granedoy/)
 * (@granedoy)
 * [2 years, 5 months ago](https://wordpress.org/support/topic/player-list-not-sortingf-correctly/#post-17510343)
 * Try this to see if it works for you. In the list of players, assign a number 
   to the order of the post in alphabetical order as you wish. I think in theory
   when you filter bat appearances, it should be placed how you want.

Viewing 9 replies - 1 through 9 (of 9 total)