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. */
|
/** @var string The date to range to. */
|
||||||
public $to;
|
public $to;
|
||||||
|
|
||||||
|
/** @var int The competition ID. */
|
||||||
|
public $league;
|
||||||
|
|
||||||
|
/** @var int The season ID. */
|
||||||
|
public $season;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* __construct function.
|
* __construct function.
|
||||||
*
|
*
|
||||||
@@ -59,9 +65,8 @@ class SP_Calendar extends SP_Custom_Post {
|
|||||||
if ( ! $this->from )
|
if ( ! $this->from )
|
||||||
$this->from = get_post_meta( $this->ID, 'sp_date_from', true );
|
$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 );
|
$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;
|
||||||
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 ( $pagenow != 'post-new.php' ):
|
||||||
if ( $this->ID ):
|
if ( $this->ID ):
|
||||||
$leagues = get_the_terms( $this->ID, 'sp_league' );
|
$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 ) );
|
$teams = array_filter( get_post_meta( $this->ID, 'sp_team', false ) );
|
||||||
$table = get_post_meta( $this->ID, 'sp_table', true );
|
$table = get_post_meta( $this->ID, 'sp_table', true );
|
||||||
|
|
||||||
if ( $leagues ):
|
if ( ! isset( $league_ids ) && $leagues ):
|
||||||
$league_ids = array();
|
$league_ids = array();
|
||||||
foreach( $leagues as $league ):
|
foreach( $leagues as $league ):
|
||||||
$league_ids[] = $league->term_id;
|
$league_ids[] = $league->term_id;
|
||||||
endforeach;
|
endforeach;
|
||||||
|
endif;
|
||||||
|
|
||||||
|
if ( isset( $league_ids ) ) {
|
||||||
$args['tax_query'][] = array(
|
$args['tax_query'][] = array(
|
||||||
'taxonomy' => 'sp_league',
|
'taxonomy' => 'sp_league',
|
||||||
'field' => 'id',
|
'field' => 'id',
|
||||||
'terms' => $league_ids
|
'terms' => $league_ids
|
||||||
);
|
);
|
||||||
endif;
|
}
|
||||||
|
|
||||||
if ( $seasons ):
|
if ( ! isset( $season_ids ) && $seasons ):
|
||||||
$season_ids = array();
|
$season_ids = array();
|
||||||
foreach( $seasons as $season ):
|
foreach( $seasons as $season ):
|
||||||
$season_ids[] = $season->term_id;
|
$season_ids[] = $season->term_id;
|
||||||
endforeach;
|
endforeach;
|
||||||
|
endif;
|
||||||
|
|
||||||
|
if ( isset( $season_ids ) ) {
|
||||||
$args['tax_query'][] = array(
|
$args['tax_query'][] = array(
|
||||||
'taxonomy' => 'sp_season',
|
'taxonomy' => 'sp_season',
|
||||||
'field' => 'id',
|
'field' => 'id',
|
||||||
'terms' => $season_ids
|
'terms' => $season_ids
|
||||||
);
|
);
|
||||||
endif;
|
}
|
||||||
|
|
||||||
if ( $venues ):
|
if ( $venues ):
|
||||||
$venue_ids = array();
|
$venue_ids = array();
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ $defaults = array(
|
|||||||
'date' => 'default',
|
'date' => 'default',
|
||||||
'date_from' => 'default',
|
'date_from' => 'default',
|
||||||
'date_to' => 'default',
|
'date_to' => 'default',
|
||||||
|
'league' => null,
|
||||||
|
'season' => null,
|
||||||
'number' => -1,
|
'number' => -1,
|
||||||
'link_teams' => get_option( 'sportspress_link_teams', 'no' ) == 'yes' ? true : false,
|
'link_teams' => get_option( 'sportspress_link_teams', 'no' ) == 'yes' ? true : false,
|
||||||
'link_events' => get_option( 'sportspress_link_events', 'yes' ) == '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;
|
$calendar->from = $date_from;
|
||||||
if ( $date_to != 'default' )
|
if ( $date_to != 'default' )
|
||||||
$calendar->to = $date_to;
|
$calendar->to = $date_to;
|
||||||
|
if ( $league )
|
||||||
|
$calendar->league = $league;
|
||||||
|
if ( $season )
|
||||||
|
$calendar->season = $season;
|
||||||
if ( $order != 'default' )
|
if ( $order != 'default' )
|
||||||
$calendar->order = $order;
|
$calendar->order = $order;
|
||||||
$data = $calendar->data();
|
$data = $calendar->data();
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ $defaults = array(
|
|||||||
'date' => 'default',
|
'date' => 'default',
|
||||||
'date_from' => 'default',
|
'date_from' => 'default',
|
||||||
'date_to' => 'default',
|
'date_to' => 'default',
|
||||||
|
'league' => null,
|
||||||
|
'season' => null,
|
||||||
'initial' => true,
|
'initial' => true,
|
||||||
'caption_tag' => 'h4',
|
'caption_tag' => 'h4',
|
||||||
'show_all_events_link' => false,
|
'show_all_events_link' => false,
|
||||||
@@ -34,6 +36,10 @@ if ( isset( $id ) ):
|
|||||||
$calendar->from = $date_from;
|
$calendar->from = $date_from;
|
||||||
if ( $date_to != 'default' )
|
if ( $date_to != 'default' )
|
||||||
$calendar->to = $date_to;
|
$calendar->to = $date_to;
|
||||||
|
if ( $league )
|
||||||
|
$calendar->league = $league;
|
||||||
|
if ( $season )
|
||||||
|
$calendar->season = $season;
|
||||||
$events = $calendar->data();
|
$events = $calendar->data();
|
||||||
$event_ids = array();
|
$event_ids = array();
|
||||||
foreach ( $events as $event ):
|
foreach ( $events as $event ):
|
||||||
|
|||||||
@@ -16,6 +16,8 @@ $defaults = array(
|
|||||||
'date' => 'default',
|
'date' => 'default',
|
||||||
'date_from' => 'default',
|
'date_from' => 'default',
|
||||||
'date_to' => 'default',
|
'date_to' => 'default',
|
||||||
|
'league' => null,
|
||||||
|
'season' => null,
|
||||||
'number' => -1,
|
'number' => -1,
|
||||||
'show_team_logo' => get_option( 'sportspress_event_list_show_logos', 'no' ) == 'yes' ? true : false,
|
'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,
|
'link_events' => get_option( 'sportspress_link_events', 'yes' ) == 'yes' ? true : false,
|
||||||
@@ -42,6 +44,10 @@ if ( $date_from != 'default' )
|
|||||||
$calendar->from = $date_from;
|
$calendar->from = $date_from;
|
||||||
if ( $date_to != 'default' )
|
if ( $date_to != 'default' )
|
||||||
$calendar->to = $date_to;
|
$calendar->to = $date_to;
|
||||||
|
if ( $league )
|
||||||
|
$calendar->league = $league;
|
||||||
|
if ( $season )
|
||||||
|
$calendar->season = $season;
|
||||||
if ( $order != 'default' )
|
if ( $order != 'default' )
|
||||||
$calendar->order = $order;
|
$calendar->order = $order;
|
||||||
$data = $calendar->data();
|
$data = $calendar->data();
|
||||||
|
|||||||
Reference in New Issue
Block a user