Enable events filtering in calendars based on Players participated (either team vs team or player vs player)

This commit is contained in:
savvasha
2019-06-16 14:21:04 +03:00
parent 6e15f341ed
commit e1bfbac3a2
2 changed files with 31 additions and 0 deletions

View File

@@ -31,6 +31,7 @@ class SP_Meta_Box_Calendar_Details {
$event_format = get_post_meta( $post->ID, 'sp_event_format', true ); $event_format = get_post_meta( $post->ID, 'sp_event_format', true );
$day = get_post_meta( $post->ID, 'sp_day', true ); $day = get_post_meta( $post->ID, 'sp_day', true );
$teams = get_post_meta( $post->ID, 'sp_team', false ); $teams = get_post_meta( $post->ID, 'sp_team', false );
$players = get_post_meta( $post->ID, 'sp_player', false );
$table_id = get_post_meta( $post->ID, 'sp_table', true ); $table_id = get_post_meta( $post->ID, 'sp_table', true );
$orderby = get_post_meta( $post->ID, 'sp_orderby', true ); $orderby = get_post_meta( $post->ID, 'sp_orderby', true );
$order = get_post_meta( $post->ID, 'sp_order', true ); $order = get_post_meta( $post->ID, 'sp_order', true );
@@ -125,6 +126,24 @@ class SP_Meta_Box_Calendar_Details {
endif; endif;
?> ?>
</p> </p>
<p><strong><?php _e( 'Player', 'sportspress' ); ?></strong></p>
<p>
<?php
$args = array(
'post_type' => 'sp_player',
'name' => 'sp_player[]',
'selected' => $players,
'values' => 'ID',
'class' => 'widefat',
'property' => 'multiple',
'chosen' => true,
'placeholder' => __( 'All', 'sportspress' ),
);
if ( ! sp_dropdown_pages( $args ) ):
sp_post_adder( 'sp_player', __( 'Add New', 'sportspress' ) );
endif;
?>
</p>
<p><strong><?php _e( 'Sort by', 'sportspress' ); ?></strong></p> <p><strong><?php _e( 'Sort by', 'sportspress' ); ?></strong></p>
<p> <p>
<select name="sp_orderby"> <select name="sp_orderby">
@@ -163,5 +182,6 @@ class SP_Meta_Box_Calendar_Details {
update_post_meta( $post_id, 'sp_orderby', sp_array_value( $_POST, 'sp_orderby', null ) ); update_post_meta( $post_id, 'sp_orderby', sp_array_value( $_POST, 'sp_orderby', null ) );
update_post_meta( $post_id, 'sp_order', sp_array_value( $_POST, 'sp_order', null ) ); update_post_meta( $post_id, 'sp_order', sp_array_value( $_POST, 'sp_order', null ) );
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) ); sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_player', sp_array_value( $_POST, 'sp_player', array() ) );
} }
} }

View File

@@ -334,6 +334,7 @@ class SP_Calendar extends SP_Secondary_Post {
$seasons = get_the_terms( $this->ID, 'sp_season' ); $seasons = get_the_terms( $this->ID, 'sp_season' );
$venues = get_the_terms( $this->ID, 'sp_venue' ); $venues = get_the_terms( $this->ID, 'sp_venue' );
$teams = array_filter( get_post_meta( $this->ID, 'sp_team', false ) ); $teams = array_filter( get_post_meta( $this->ID, 'sp_team', false ) );
$players = array_filter( get_post_meta( $this->ID, 'sp_player', false ) );
$table = get_post_meta( $this->ID, 'sp_table', true ); $table = get_post_meta( $this->ID, 'sp_table', true );
if ( ! isset( $league_ids ) ) $league_ids = array(); if ( ! isset( $league_ids ) ) $league_ids = array();
@@ -395,6 +396,16 @@ class SP_Calendar extends SP_Secondary_Post {
), ),
); );
} }
if ( ! empty( $players ) ) {
$args['meta_query'] = array(
array(
'key' => 'sp_player',
'value' => $players,
'compare' => 'IN',
),
);
}
if ( $this->event) { if ( $this->event) {
$args['p'] = $this->event; $args['p'] = $this->event;