From 9295074c0c4b828e824980b250356aefc3e832c6 Mon Sep 17 00:00:00 2001 From: Brian Miyaji Date: Thu, 19 Jun 2014 00:27:37 +1000 Subject: [PATCH] Filter post checklists by league and season --- includes/sp-core-functions.php | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/includes/sp-core-functions.php b/includes/sp-core-functions.php index 5f51ba53..8af48c2e 100644 --- a/includes/sp-core-functions.php +++ b/includes/sp-core-functions.php @@ -657,14 +657,32 @@ if ( !function_exists( 'sp_post_checklist' ) ) {
  • $meta, 'number' => 0 ) ); if ( empty( $posts ) ): - $query = array( 'post_type' => $meta, 'numberposts' => -1, 'post_per_page' => -1 ); + $query = array( 'post_type' => $meta, 'numberposts' => -1, 'post_per_page' => -1, 'tax_query' => array( 'relation' => 'AND' ) ); if ( $meta == 'sp_player' ): $query['meta_key'] = 'sp_number'; $query['orderby'] = 'meta_value_num'; $query['order'] = 'ASC'; endif; + + // Filter by league and season when available + $league = sp_get_the_term_id( $post_id, 'sp_league', 0 ); + if ( $league ): + $query['tax_query'][] = array( + 'taxonomy' => 'sp_league', + 'field' => 'id', + 'terms' => $league + ); + endif; + $season = sp_get_the_term_id( $post_id, 'sp_season', 0 ); + if ( $season ): + $query['tax_query'][] = array( + 'taxonomy' => 'sp_season', + 'field' => 'id', + 'terms' => $season + ); + endif; + $posts = get_posts( $query ); endif; foreach ( $posts as $post ):