Make league table show played games automatically from event count
This commit is contained in:
24
team.php
24
team.php
@@ -40,15 +40,31 @@ function sp_team_stats_meta( $post ) {
|
||||
$leagues = (array)get_the_terms( $post->ID, 'sp_league' );
|
||||
$stats = (array)get_post_meta( $post->ID, 'sp_stats', true );
|
||||
|
||||
$keys = array( 0 );
|
||||
// Generate array of all league ids
|
||||
$league_ids = array( 0 );
|
||||
foreach ( $leagues as $key => $value ):
|
||||
if ( is_object( $value ) && property_exists( $value, 'term_id' ) )
|
||||
$keys[] = $value->term_id;
|
||||
$league_ids[] = $value->term_id;
|
||||
endforeach;
|
||||
|
||||
// Get all leagues populated with stats where availabled
|
||||
$data = sp_array_combine( $league_ids, sp_array_value( $stats, 0, array() ) );
|
||||
|
||||
// Generate array of placeholder values for each league
|
||||
$placeholders = array();
|
||||
foreach ( $league_ids as $league_id ):
|
||||
$args = array(
|
||||
'post_type' => 'sp_event',
|
||||
'meta_key' => 'sp_team',
|
||||
'meta_value' => $post->ID,
|
||||
'taxonomy' => 'sp_league',
|
||||
'terms' => $league_id
|
||||
);
|
||||
$placeholders[ $league_id ] = sp_get_stats_row( $args );
|
||||
endforeach;
|
||||
|
||||
$data = sp_array_combine( $keys, sp_array_value( $stats, 0, array() ) );
|
||||
?>
|
||||
<?php sp_stats_table( $data, array(), 0, array( 'League', 'P', 'W', 'D', 'L', 'F', 'A', 'GD', 'Pts' ), true, 'sp_league' );
|
||||
<?php sp_stats_table( $data, $placeholders, 0, array( 'League', 'P', 'W', 'D', 'L', 'F', 'A', 'GD', 'Pts' ), true, 'sp_league' );
|
||||
|
||||
sp_nonce();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user