From c5dd81604828db03ac4ca6e67eb3924772c49e10 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Sat, 4 Feb 2017 01:37:04 +1100 Subject: [PATCH] Check if team ID's in event results match up with team ID's of that event. --- includes/class-sp-league-table.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/includes/class-sp-league-table.php b/includes/class-sp-league-table.php index f84b2075..67b28f57 100644 --- a/includes/class-sp-league-table.php +++ b/includes/class-sp-league-table.php @@ -67,6 +67,7 @@ class SP_League_Table extends SP_Custom_Post{ 'tax_query' => array( 'relation' => 'AND', ), + 'fields' => 'ids', ); if ( $league_ids ): @@ -85,13 +86,7 @@ class SP_League_Table extends SP_Custom_Post{ ); endif; - $teams = get_posts( $args ); - - if ( $teams && is_array( $teams ) ) { - foreach ( $teams as $team ) { - $team_ids[] = $team->ID; - } - } + $team_ids = get_posts( $args ); } else { $team_ids = (array)get_post_meta( $this->ID, 'sp_team', false ); } @@ -260,6 +255,7 @@ class SP_League_Table extends SP_Custom_Post{ // Event loop foreach ( $events as $event ): + $teams = (array)get_post_meta( $event->ID, 'sp_team', false ); $results = (array)get_post_meta( $event->ID, 'sp_results', true ); $minutes = get_post_meta( $event->ID, 'sp_minutes', true ); if ( $minutes === '' ) $minutes = get_option( 'sportspress_event_minutes', 90 ); @@ -268,6 +264,8 @@ class SP_League_Table extends SP_Custom_Post{ foreach ( $results as $team_id => $team_result ): + if ( ! in_array( $team_id, $teams ) ) continue; + if ( ! in_array( $team_id, $team_ids ) ) { $i++; continue;