Advertisement
petehayman

get_player_stats Function Update

Oct 24th, 2018
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.10 KB | None | 0 0
  1. // Player Stats
  2. function get_apps_data( $playerID ) {
  3.     $apps = 0;  // Total appearances.
  4.     $subs = 0;  // Total sub-appearances.
  5.     $goals = 0; // Total goals.
  6.  
  7.     $query = new WP_Query( array( 'post_type' => 'match' ) );
  8.     $posts = $query->posts;
  9.  
  10.     foreach($posts as $post) {
  11.         for ( $n = 1; $n <= 18; $n++ ) {
  12.             // Check if the player is $playerID
  13.             $pl = get_post_meta( $post->ID, 'pl' . $n, true );
  14.             if ( $playerID == $pl ) {
  15.                 $apps++;
  16.  
  17.                 // Check his sub-out appearance.
  18.                 $so = get_post_meta( $post->ID, 'so' . $n, true );
  19.                 $subs += $so ? 1 : 0;
  20.  
  21.                 // Check his sub-in appearance.
  22.                 $si = get_post_meta( $post->ID, 'si' . $n, true );
  23.                 $subs += $si ? 1 : 0;
  24.             }
  25.  
  26.             // Check if he scored goal {$n}-th.
  27.             $s = get_post_meta( $post->ID, 's' . $n, true );
  28.             if ( $playerID == $s ) {
  29.                 $goals++;
  30.             }
  31.         }
  32.     }
  33.     wp_reset_query();
  34.  
  35.     return compact( 'apps', 'subs', 'goals' );
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement