diff --git a/includes/class-sp-calendar.php b/includes/class-sp-calendar.php index 84bcf1e8..9dd05a49 100644 --- a/includes/class-sp-calendar.php +++ b/includes/class-sp-calendar.php @@ -28,6 +28,12 @@ class SP_Calendar extends SP_Custom_Post { /** @var string The date to range to. */ public $to; + /** @var int The competition ID. */ + public $league; + + /** @var int The season ID. */ + public $season; + /** * __construct function. * @@ -59,9 +65,8 @@ class SP_Calendar extends SP_Custom_Post { if ( ! $this->from ) $this->from = get_post_meta( $this->ID, 'sp_date_from', true ); - if ( ! $this->to ): + if ( ! $this->to ) $this->to = get_post_meta( $this->ID, 'sp_date_to', true ); - endif; } /** @@ -98,6 +103,14 @@ class SP_Calendar extends SP_Custom_Post { endif; endif; + if ( $this->league ): + $league_ids = array( $this->league ); + endif; + + if ( $this->season ): + $season_ids = array( $this->season ); + endif; + if ( $pagenow != 'post-new.php' ): if ( $this->ID ): $leagues = get_the_terms( $this->ID, 'sp_league' ); @@ -106,29 +119,35 @@ class SP_Calendar extends SP_Custom_Post { $teams = array_filter( get_post_meta( $this->ID, 'sp_team', false ) ); $table = get_post_meta( $this->ID, 'sp_table', true ); - if ( $leagues ): + if ( ! isset( $league_ids ) && $leagues ): $league_ids = array(); foreach( $leagues as $league ): $league_ids[] = $league->term_id; endforeach; + endif; + + if ( isset( $league_ids ) ) { $args['tax_query'][] = array( 'taxonomy' => 'sp_league', 'field' => 'id', 'terms' => $league_ids ); - endif; + } - if ( $seasons ): + if ( ! isset( $season_ids ) && $seasons ): $season_ids = array(); foreach( $seasons as $season ): $season_ids[] = $season->term_id; endforeach; + endif; + + if ( isset( $season_ids ) ) { $args['tax_query'][] = array( 'taxonomy' => 'sp_season', 'field' => 'id', 'terms' => $season_ids ); - endif; + } if ( $venues ): $venue_ids = array(); diff --git a/templates/event-blocks.php b/templates/event-blocks.php index 7c3fe289..72e24bc2 100644 --- a/templates/event-blocks.php +++ b/templates/event-blocks.php @@ -18,6 +18,8 @@ $defaults = array( 'date' => 'default', 'date_from' => 'default', 'date_to' => 'default', + 'league' => null, + 'season' => null, 'number' => -1, 'link_teams' => get_option( 'sportspress_link_teams', 'no' ) == 'yes' ? true : false, 'link_events' => get_option( 'sportspress_link_events', 'yes' ) == 'yes' ? true : false, @@ -42,6 +44,10 @@ if ( $date_from != 'default' ) $calendar->from = $date_from; if ( $date_to != 'default' ) $calendar->to = $date_to; +if ( $league ) + $calendar->league = $league; +if ( $season ) + $calendar->season = $season; if ( $order != 'default' ) $calendar->order = $order; $data = $calendar->data(); diff --git a/templates/event-calendar.php b/templates/event-calendar.php index 85fd0889..24273562 100644 --- a/templates/event-calendar.php +++ b/templates/event-calendar.php @@ -17,6 +17,8 @@ $defaults = array( 'date' => 'default', 'date_from' => 'default', 'date_to' => 'default', + 'league' => null, + 'season' => null, 'initial' => true, 'caption_tag' => 'h4', 'show_all_events_link' => false, @@ -34,6 +36,10 @@ if ( isset( $id ) ): $calendar->from = $date_from; if ( $date_to != 'default' ) $calendar->to = $date_to; + if ( $league ) + $calendar->league = $league; + if ( $season ) + $calendar->season = $season; $events = $calendar->data(); $event_ids = array(); foreach ( $events as $event ): diff --git a/templates/event-list.php b/templates/event-list.php index 19404e91..3112e0c9 100644 --- a/templates/event-list.php +++ b/templates/event-list.php @@ -16,6 +16,8 @@ $defaults = array( 'date' => 'default', 'date_from' => 'default', 'date_to' => 'default', + 'league' => null, + 'season' => null, 'number' => -1, 'show_team_logo' => get_option( 'sportspress_event_list_show_logos', 'no' ) == 'yes' ? true : false, 'link_events' => get_option( 'sportspress_link_events', 'yes' ) == 'yes' ? true : false, @@ -42,6 +44,10 @@ if ( $date_from != 'default' ) $calendar->from = $date_from; if ( $date_to != 'default' ) $calendar->to = $date_to; +if ( $league ) + $calendar->league = $league; +if ( $season ) + $calendar->season = $season; if ( $order != 'default' ) $calendar->order = $order; $data = $calendar->data();