Merge pull request #360 from ThemeBoy/feature-player-list-nationality

Enable Player List filtering by Nationality
This commit is contained in:
Brian Miyaji
2020-04-04 13:23:15 +11:00
committed by GitHub
2 changed files with 32 additions and 1 deletions

View File

@@ -34,6 +34,9 @@ class SP_Meta_Box_List_Details {
$date_to = get_post_meta( $post->ID, 'sp_date_to', true ); $date_to = get_post_meta( $post->ID, 'sp_date_to', true );
$date_past = get_post_meta( $post->ID, 'sp_date_past', true ); $date_past = get_post_meta( $post->ID, 'sp_date_past', true );
$date_relative = get_post_meta( $post->ID, 'sp_date_relative', true ); $date_relative = get_post_meta( $post->ID, 'sp_date_relative', true );
$continents = SP()->countries->continents;
$nationalities = get_post_meta( $post->ID, 'sp_nationality', false );
$default_nationality = get_option( 'sportspress_default_nationality' , false );
?> ?>
<div> <div>
<p><strong><?php _e( 'Heading', 'sportspress' ); ?></strong></p> <p><strong><?php _e( 'Heading', 'sportspress' ); ?></strong></p>
@@ -98,6 +101,19 @@ class SP_Meta_Box_List_Details {
<option value="past" <?php selected( 'past', $era ); ?>><?php _e( 'Past', 'sportspress' ); ?></option> <option value="past" <?php selected( 'past', $era ); ?>><?php _e( 'Past', 'sportspress' ); ?></option>
</select> </select>
</p> </p>
<p><strong><?php _e( 'Nationality', 'sportspress' ); ?></strong></p>
<p>
<select id="sp_nationality" name="sp_nationality[]" data-placeholder="<?php printf( __( 'Select %s', 'sportspress' ), __( 'Nationality', 'sportspress' ) ); ?>" class="widefat chosen-select<?php if ( is_rtl() ): ?> chosen-rtl<?php endif; ?>" multiple="multiple">
<option value=""></option>
<?php foreach ( $continents as $continent => $countries ): ?>
<optgroup label="<?php echo $continent; ?>">
<?php foreach ( $countries as $code => $country ): ?>
<option value="<?php echo $code; ?>" <?php selected ( in_array( $code, $nationalities ) ); ?>><?php echo $country; ?></option>
<?php endforeach; ?>
</optgroup>
<?php endforeach; ?>
</select>
</p>
<p><strong><?php _e( 'Grouping', 'sportspress' ); ?></strong></p> <p><strong><?php _e( 'Grouping', 'sportspress' ); ?></strong></p>
<p> <p>
<select name="sp_grouping"> <select name="sp_grouping">
@@ -178,5 +194,6 @@ class SP_Meta_Box_List_Details {
update_post_meta( $post_id, 'sp_select', sp_array_value( $_POST, 'sp_select', array() ) ); update_post_meta( $post_id, 'sp_select', sp_array_value( $_POST, 'sp_select', array() ) );
update_post_meta( $post_id, 'sp_number', sp_array_value( $_POST, 'sp_number', array() ) ); update_post_meta( $post_id, 'sp_number', sp_array_value( $_POST, 'sp_number', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_player', sp_array_value( $_POST, 'sp_player', array() ) ); sp_update_post_meta_recursive( $post_id, 'sp_player', sp_array_value( $_POST, 'sp_player', array() ) );
sp_update_post_meta_recursive( $post_id, 'sp_nationality', sp_array_value( $_POST, 'sp_nationality', array() ) );
} }
} }

View File

@@ -59,6 +59,7 @@ class SP_Player_List extends SP_Secondary_Post {
$crop = get_post_meta( $this->ID, 'sp_crop', true ); $crop = get_post_meta( $this->ID, 'sp_crop', true );
$order = get_post_meta( $this->ID, 'sp_order', true ); $order = get_post_meta( $this->ID, 'sp_order', true );
$select = get_post_meta( $this->ID, 'sp_select', true ); $select = get_post_meta( $this->ID, 'sp_select', true );
$nationalities = get_post_meta( $this->ID, 'sp_nationality', false );
$this->date = $this->__get( 'date' ); $this->date = $this->__get( 'date' );
@@ -110,6 +111,9 @@ class SP_Player_List extends SP_Secondary_Post {
'tax_query' => array( 'tax_query' => array(
'relation' => 'AND', 'relation' => 'AND',
), ),
'meta_query' => array(
'relation' => 'AND',
),
); );
if ( $league_ids ): if ( $league_ids ):
@@ -138,7 +142,7 @@ class SP_Player_List extends SP_Secondary_Post {
$team_key = 'sp_past_team'; $team_key = 'sp_past_team';
break; break;
endswitch; endswitch;
$args['meta_query'] = array( $args['meta_query'][] = array(
array( array(
'key' => $team_key, 'key' => $team_key,
'value' => $team 'value' => $team
@@ -153,6 +157,16 @@ class SP_Player_List extends SP_Secondary_Post {
'terms' => $position_ids 'terms' => $position_ids
); );
endif; endif;
if ( $nationalities ):
$args['meta_query'][] = array(
array(
'key' => 'sp_nationality',
'value' => $nationalities,
'compare' => 'IN'
),
);
endif;
$args = apply_filters( 'sportspress_player_list_args', $args, $team ); $args = apply_filters( 'sportspress_player_list_args', $args, $team );