Enable multiple team selection in calendars

This commit is contained in:
Brian Miyaji
2015-03-28 13:18:46 +11:00
parent 057d17a875
commit 0b9cd325a1
3 changed files with 29 additions and 68 deletions

View File

@@ -557,16 +557,6 @@ jQuery(document).ready(function($){
}); });
$(".sp-date-selector select").trigger("change"); $(".sp-date-selector select").trigger("change");
// Show or hide league table selector
$(".sp-team-selector .sp-team-picker select").change(function() {
console.log( $(this) );
if ( $(this).val() == "table" ) {
$(this).closest(".sp-team-selector").find(".sp-league-table-picker").show();
} else {
$(this).closest(".sp-team-selector").find(".sp-league-table-picker").hide();
}
}).trigger("change");
// Apply color scheme // Apply color scheme
$(".sp-color-option").on("click", function() { $(".sp-color-option").on("click", function() {
colors = $(this).find("label").data("sp-colors").split(","); colors = $(this).find("label").data("sp-colors").split(",");

View File

@@ -24,7 +24,7 @@ class SP_Meta_Box_Calendar_Details {
$date = get_post_meta( $post->ID, 'sp_date', true ); $date = get_post_meta( $post->ID, 'sp_date', true );
$date_from = get_post_meta( $post->ID, 'sp_date_from', true ); $date_from = get_post_meta( $post->ID, 'sp_date_from', true );
$date_to = get_post_meta( $post->ID, 'sp_date_to', true ); $date_to = get_post_meta( $post->ID, 'sp_date_to', true );
$team_id = get_post_meta( $post->ID, 'sp_team', true ); $teams = get_post_meta( $post->ID, 'sp_team', false );
$table_id = get_post_meta( $post->ID, 'sp_table', true ); $table_id = get_post_meta( $post->ID, 'sp_table', true );
$order = get_post_meta( $post->ID, 'sp_order', true ); $order = get_post_meta( $post->ID, 'sp_order', true );
?> ?>
@@ -63,40 +63,24 @@ class SP_Meta_Box_Calendar_Details {
sp_taxonomy_field( $taxonomy, $post, true ); sp_taxonomy_field( $taxonomy, $post, true );
} }
?> ?>
<div class="sp-team-selector"> <p><strong><?php _e( 'Team', 'sportspress' ); ?></strong></p>
<p><strong><?php _e( 'Team', 'sportspress' ); ?></strong></p> <p>
<p class="sp-team-picker"> <?php
<?php $args = array(
$args = array( 'post_type' => 'sp_team',
'show_option_all' => __( 'All', 'sportspress' ), 'name' => 'sp_team[]',
'post_type' => 'sp_team', 'selected' => $teams,
'name' => 'sp_team', 'values' => 'ID',
'selected' => $team_id, 'class' => 'widefat',
'values' => 'ID', 'property' => 'multiple',
'append_options' => array( 'chosen' => true,
'table' => sprintf( __( 'Select %s:', 'sportspress' ), __( 'League Table', 'sportspress' ) ), 'placeholder' => __( 'All', 'sportspress' ),
), );
); if ( ! sp_dropdown_pages( $args ) ):
if ( ! sp_dropdown_pages( $args ) ): sp_post_adder( 'sp_team', __( 'Add New', 'sportspress' ) );
sp_post_adder( 'sp_team', __( 'Add New', 'sportspress' ) ); endif;
endif; ?>
?> </p>
</p>
<p class="sp-league-table-picker">
<?php
$args = array(
'show_option_all' => __( 'All', 'sportspress' ),
'post_type' => 'sp_table',
'name' => 'sp_table',
'selected' => $table_id,
'values' => 'ID',
);
if ( ! sp_dropdown_pages( $args ) ):
sp_post_adder( 'sp_table', __( 'Add New', 'sportspress' ) );
endif;
?>
</p>
</div>
<p><strong><?php _e( 'Sort Order', 'sportspress' ); ?></strong></p> <p><strong><?php _e( 'Sort Order', 'sportspress' ); ?></strong></p>
<p> <p>
<select name="sp_order"> <select name="sp_order">
@@ -117,7 +101,6 @@ class SP_Meta_Box_Calendar_Details {
update_post_meta( $post_id, 'sp_date_from', sp_array_value( $_POST, 'sp_date_from', null ) ); update_post_meta( $post_id, 'sp_date_from', sp_array_value( $_POST, 'sp_date_from', null ) );
update_post_meta( $post_id, 'sp_date_to', sp_array_value( $_POST, 'sp_date_to', null ) ); update_post_meta( $post_id, 'sp_date_to', sp_array_value( $_POST, 'sp_date_to', null ) );
update_post_meta( $post_id, 'sp_order', sp_array_value( $_POST, 'sp_order', array() ) ); update_post_meta( $post_id, 'sp_order', sp_array_value( $_POST, 'sp_order', array() ) );
update_post_meta( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', 0 ) ); sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
update_post_meta( $post_id, 'sp_table', sp_array_value( $_POST, 'sp_table', 0 ) );
} }
} }

View File

@@ -103,7 +103,7 @@ class SP_Calendar extends SP_Custom_Post {
$leagues = get_the_terms( $this->ID, 'sp_league' ); $leagues = get_the_terms( $this->ID, 'sp_league' );
$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' );
$team = get_post_meta( $this->ID, 'sp_team', true ); $teams = 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 ( $leagues ):
@@ -142,26 +142,14 @@ class SP_Calendar extends SP_Custom_Post {
); );
endif; endif;
if ( $team ): if ( ! empty( $teams ) ):
if ( 'table' !== $team ): $args['meta_query'] = array(
$args['meta_query'] = array( array(
array( 'key' => 'sp_team',
'key' => 'sp_team', 'value' => $teams,
'value' => $team, 'compare' => 'IN',
), ),
); );
elseif ( $table ) :
$teams = get_post_meta( $table, 'sp_team' );
$teams = array_filter( $teams );
$args['meta_query'] = array(
array(
'key' => 'sp_team',
'value' => $teams,
'compare' => 'IN'
),
);
endif;
endif; endif;
endif; endif;