function points_table_team_shortcode($atts) { // Shortcode attributes: match_id $atts = shortcode_atts( [ 'match_id' => '', // Match ID to fetch data for. ], $atts ); if (empty($atts['match_id'])) { return '

Error: match_id is required.

'; } // Fetch match data using match_id to get competition_id and teams $match_url = "https://rest.entitysport.com/v2/matches/{$atts['match_id']}/info/?token=" . GENERATE_DRAFT_TOKEN; $match_response = wp_remote_get($match_url); if (is_wp_error($match_response)) { return '

Error: Unable to fetch match data.

'; } $match_data = wp_remote_retrieve_body($match_response); $match_data = json_decode($match_data, true); // Check if competition data is available if (isset($match_data['response']['competition']['cid'])) { $competition_id = $match_data['response']['competition']['cid']; } else { return '

Error: No competition data found for the selected match.

'; } // Extract team IDs (home_team and away_team) $home_team_id = $match_data['response']['teama']['team_id'] ?? null; $away_team_id = $match_data['response']['teamb']['team_id'] ?? null; if (!$home_team_id || !$away_team_id) { return '

Error: Unable to fetch teams for the selected match.

'; } // Fetch standings data using competition_id $standings_url = "https://rest.entitysport.com/v2/competitions/{$competition_id}/standings/?token=" . GENERATE_DRAFT_TOKEN; $standings_response = wp_remote_get($standings_url); if (is_wp_error($standings_response)) { return '

Error: Unable to fetch standings data.

'; } $standings_data = wp_remote_retrieve_body($standings_response); $standings_data = json_decode($standings_data, true); // Check if standings data is available if (isset($standings_data['response']['standings'][0]['standings']) && !empty($standings_data['response']['standings'][0]['standings'])) { // Build an array of teams that are involved in the match $teams = []; foreach ($standings_data['response']['standings'][0]['standings'] as $team) { $team_id = $team['team']['tid'] ?? null; // Fixed key for team ID if ($team_id === $home_team_id || $team_id === $away_team_id) { $teams[] = [ 'team_name' => $team['team']['title'] ?? 'Unknown Team', 'matches_played' => $team['played'] ?? 'N/A', 'wins' => $team['win'] ?? 'N/A', 'losses' => $team['loss'] ?? 'N/A', 'points' => $team['points'] ?? 'N/A', 'last_five_results' => $team['lastfivematchresult'] ?? 'N/A' ]; } } // Sort the teams array by points in descending order usort($teams, function($a, $b) { return $b['points'] - $a['points']; }); // Auto description paragraph before the table $description = '

Below is the points table for the current match between ' . esc_html($match_data['response']['teama']['name']) . ' and ' . esc_html($match_data['response']['teamb']['name']) . '. The teams are ranked based on their points.

'; // Add the detailed performance description for each team foreach ($teams as $team) { $last_five_results = $team['last_five_results']; $win_count = substr_count($last_five_results, 'W'); $loss_count = substr_count($last_five_results, 'L'); $win_ratio = ($win_count / 5) * 100; // Win ratio in percentage // Determine form based on win ratio if ($win_ratio >= 60 && $win_ratio <= 70) { $form_comment = 'doing well recently'; } elseif ($win_ratio >= 10 && $win_ratio <= 30) { $form_comment = 'struggling recently'; } else { $form_comment = 'showing mixed results'; } $description .= sprintf( '

The %s have played %d matches, won %d, and lost %d, with a total of %d points. They have been %s, winning %d out of their last 5 matches.

', esc_html($team['team_name']), $team['matches_played'], $team['wins'], $team['losses'], $team['points'], $form_comment, $win_count ); } // Build the table for standings $output = $description; // Add the description $output .= '
'; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; // Loop through each team in the sorted array and display the data foreach ($teams as $team) { $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; } $output .= ''; $output .= '
TeamMatchesWonLostPointsLast 5 Results
' . esc_html($team['team_name']) . '' . esc_html($team['matches_played']) . '' . esc_html($team['wins']) . '' . esc_html($team['losses']) . '' . esc_html($team['points']) . '' . esc_html($team['last_five_results']) . '
'; $output .= '
'; return $output; } else { return '

No standings data available for the selected competition.

'; } } add_shortcode('points_table_team', 'points_table_team_shortcode');
Warning: Cannot modify header information - headers already sent by (output started at /home/myfinjex/public_html/wp-content/plugins/cricket-live-dream11/includes/venue stats/points_table_team.php:1) in /home/myfinjex/public_html/wp-includes/pluggable.php on line 1435

Warning: Cannot modify header information - headers already sent by (output started at /home/myfinjex/public_html/wp-content/plugins/cricket-live-dream11/includes/venue stats/points_table_team.php:1) in /home/myfinjex/public_html/wp-includes/pluggable.php on line 1438