Enable Player List filtering by Nationality
This commit is contained in:
@@ -34,6 +34,9 @@ class SP_Meta_Box_List_Details {
|
||||
$date_to = get_post_meta( $post->ID, 'sp_date_to', true );
|
||||
$date_past = get_post_meta( $post->ID, 'sp_date_past', 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>
|
||||
<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>
|
||||
</select>
|
||||
</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>
|
||||
<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_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_nationality', sp_array_value( $_POST, 'sp_nationality', array() ) );
|
||||
}
|
||||
}
|
||||
@@ -59,6 +59,7 @@ class SP_Player_List extends SP_Secondary_Post {
|
||||
$crop = get_post_meta( $this->ID, 'sp_crop', true );
|
||||
$order = get_post_meta( $this->ID, 'sp_order', true );
|
||||
$select = get_post_meta( $this->ID, 'sp_select', true );
|
||||
$nationalities = get_post_meta( $this->ID, 'sp_nationality', false );
|
||||
|
||||
$this->date = $this->__get( 'date' );
|
||||
|
||||
@@ -110,6 +111,9 @@ class SP_Player_List extends SP_Secondary_Post {
|
||||
'tax_query' => array(
|
||||
'relation' => 'AND',
|
||||
),
|
||||
'meta_query' => array(
|
||||
'relation' => 'AND',
|
||||
),
|
||||
);
|
||||
|
||||
if ( $league_ids ):
|
||||
@@ -138,7 +142,7 @@ class SP_Player_List extends SP_Secondary_Post {
|
||||
$team_key = 'sp_past_team';
|
||||
break;
|
||||
endswitch;
|
||||
$args['meta_query'] = array(
|
||||
$args['meta_query'][] = array(
|
||||
array(
|
||||
'key' => $team_key,
|
||||
'value' => $team
|
||||
@@ -153,6 +157,16 @@ class SP_Player_List extends SP_Secondary_Post {
|
||||
'terms' => $position_ids
|
||||
);
|
||||
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 );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user