Add era selector to player list for filtering by current or past teams

This commit is contained in:
Brian Miyaji
2016-10-31 15:25:03 +11:00
parent 21d726ff96
commit 389f7147fe
3 changed files with 36 additions and 2 deletions

View File

@@ -386,6 +386,23 @@ jQuery(document).ready(function($){
// Trigger format selector
$(".sp-format-selector select:first").change();
// Team era selector
$(".sp-team-era-selector select:first-child").change(function() {
$subselector = $(this).siblings();
// Sub settings
if($(this).val() == 0) {
$subselector.hide();
} else {
$subselector.show();
}
});
// Trigger team era selector
$(".sp-team-era-selector select:first-child").change();
// Status selector
$(".sp-status-selector select:first-child").change(function() {

View File

@@ -22,6 +22,7 @@ class SP_Meta_Box_List_Details {
$taxonomies = get_object_taxonomies( 'sp_list' );
$caption = get_post_meta( $post->ID, 'sp_caption', true );
$team_id = get_post_meta( $post->ID, 'sp_team', true );
$era = get_post_meta( $post->ID, 'sp_era', true );
$grouping = get_post_meta( $post->ID, 'sp_grouping', true );
$orderby = get_post_meta( $post->ID, 'sp_orderby', true );
$order = get_post_meta( $post->ID, 'sp_order', true );
@@ -42,7 +43,7 @@ class SP_Meta_Box_List_Details {
?>
<?php if ( apply_filters( 'sportspress_list_team_selector', true ) ) { ?>
<p><strong><?php _e( 'Team', 'sportspress' ); ?></strong></p>
<p class="sp-tab-select">
<p class="sp-tab-select sp-team-era-selector">
<?php
$args = array(
'post_type' => 'sp_team',
@@ -55,6 +56,11 @@ class SP_Meta_Box_List_Details {
sp_post_adder( 'sp_team', __( 'Add New', 'sportspress' ) );
endif;
?>
<select name="sp_era">
<option value="all" <?php selected( 'all', $era ); ?>><?php _e( 'All', 'sportspress' ); ?></option>
<option value="current" <?php selected( 'current', $era ); ?>><?php _e( 'Current', 'sportspress' ); ?></option>
<option value="past" <?php selected( 'past', $era ); ?>><?php _e( 'Past', 'sportspress' ); ?></option>
</select>
</p>
<?php } ?>
<p><strong><?php _e( 'Grouping', 'sportspress' ); ?></strong></p>
@@ -110,6 +116,7 @@ class SP_Meta_Box_List_Details {
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_caption', esc_attr( sp_array_value( $_POST, 'sp_caption', 0 ) ) );
update_post_meta( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
update_post_meta( $post_id, 'sp_era', sp_array_value( $_POST, 'sp_era', array() ) );
update_post_meta( $post_id, 'sp_grouping', sp_array_value( $_POST, 'sp_grouping', array() ) );
update_post_meta( $post_id, 'sp_orderby', sp_array_value( $_POST, 'sp_orderby', array() ) );
update_post_meta( $post_id, 'sp_order', sp_array_value( $_POST, 'sp_order', array() ) );

View File

@@ -39,6 +39,7 @@ class SP_Player_List extends SP_Custom_Post {
$season_ids = sp_get_the_term_ids( $this->ID, 'sp_season' );
$position_ids = sp_get_the_term_ids( $this->ID, 'sp_position' );
$team = get_post_meta( $this->ID, 'sp_team', true );
$era = get_post_meta( $this->ID, 'sp_era', true );
$list_stats = (array)get_post_meta( $this->ID, 'sp_players', true );
$adjustments = get_post_meta( $this->ID, 'sp_adjustments', true );
$orderby = get_post_meta( $this->ID, 'sp_orderby', true );
@@ -95,9 +96,18 @@ class SP_Player_List extends SP_Custom_Post {
endif;
if ( $team && apply_filters( 'sportspress_has_teams', true ) ):
$team_key = 'sp_team';
switch ( $era ):
case 'current':
$team_key = 'sp_current_team';
break;
case 'past':
$team_key = 'sp_past_team';
break;
endswitch;
$args['meta_query'] = array(
array(
'key' => 'sp_current_team',
'key' => $team_key,
'value' => $team
),
);