Add season and competition filter to calendars
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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 ):
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user