Add match day field to events and calendars

This commit is contained in:
Brian Miyaji
2016-08-22 01:14:32 +10:00
parent b33df471d8
commit 84e80d642a
10 changed files with 107 additions and 9 deletions

View File

@@ -25,8 +25,10 @@ class SP_Meta_Box_Calendar_Details {
$date = get_post_meta( $post->ID, 'sp_date', true );
$date_from = get_post_meta( $post->ID, 'sp_date_from', true );
$date_to = get_post_meta( $post->ID, 'sp_date_to', true );
$day = get_post_meta( $post->ID, 'sp_day', true );
$teams = get_post_meta( $post->ID, 'sp_team', false );
$table_id = get_post_meta( $post->ID, 'sp_table', true );
$orderby = get_post_meta( $post->ID, 'sp_orderby', true );
$order = get_post_meta( $post->ID, 'sp_order', true );
?>
<div>
@@ -62,6 +64,12 @@ class SP_Meta_Box_Calendar_Details {
<input type="text" class="sp-datepicker-to" name="sp_date_to" value="<?php echo $date_to ? $date_to : date_i18n( 'Y-m-d' ); ?>" size="10">
</p>
</div>
<div class="sp-event-day-field">
<p><strong><?php _e( 'Match Day', 'sportspress' ); ?></strong></p>
<p>
<input name="sp_day" type="text" class="medium-text" placeholder="<?php _e( 'All', 'sportspress' ); ?>" value="<?php echo esc_attr( $day ); ?>">
</p>
</div>
<?php
foreach ( $taxonomies as $taxonomy ) {
sp_taxonomy_field( $taxonomy, $post, true );
@@ -85,6 +93,13 @@ class SP_Meta_Box_Calendar_Details {
endif;
?>
</p>
<p><strong><?php _e( 'Sort by', 'sportspress' ); ?></strong></p>
<p>
<select name="sp_orderby">
<option value="date" <?php selected( 'date', $orderby ); ?>><?php _e( 'Date', 'sportspress' ); ?></option>
<option value="day" <?php selected( 'day', $orderby ); ?>><?php _e( 'Match Day', 'sportspress' ); ?></option>
</select>
</p>
<p><strong><?php _e( 'Sort Order', 'sportspress' ); ?></strong></p>
<p>
<select name="sp_order">
@@ -105,7 +120,9 @@ class SP_Meta_Box_Calendar_Details {
update_post_meta( $post_id, 'sp_date', sp_array_value( $_POST, 'sp_date', 0 ) );
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_order', sp_array_value( $_POST, 'sp_order', array() ) );
update_post_meta( $post_id, 'sp_day', sp_array_value( $_POST, 'sp_day', 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 ) );
sp_update_post_meta_recursive( $post_id, 'sp_team', sp_array_value( $_POST, 'sp_team', array() ) );
}
}

View File

@@ -19,10 +19,17 @@ class SP_Meta_Box_Event_Details {
* Output the metabox
*/
public static function output( $post ) {
$day = get_post_meta( $post->ID, 'sp_day', true );
$taxonomies = get_object_taxonomies( 'sp_event' );
$minutes = get_post_meta( $post->ID, 'sp_minutes', true );
?>
<?php do_action( 'sportspress_event_details_meta_box', $post ); ?>
<div class="sp-event-day-field">
<p><strong><?php _e( 'Match Day', 'sportspress' ); ?></strong></p>
<p>
<input name="sp_day" type="text" class="medium-text" placeholder="<?php _e( 'Default', 'sportspress' ); ?>" value="<?php echo esc_attr( $day ); ?>">
</p>
</div>
<div class="sp-event-minutes-field">
<p><strong><?php _e( 'Full Time', 'sportspress' ); ?></strong></p>
<p>
@@ -66,6 +73,7 @@ class SP_Meta_Box_Event_Details {
* Save meta box data
*/
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_day', sp_array_value( $_POST, 'sp_day', null ) );
update_post_meta( $post_id, 'sp_minutes', sp_array_value( $_POST, 'sp_minutes', get_option( 'sportspress_event_minutes', 90 ) ) );
$venues = array_filter( sp_array_value( sp_array_value( $_POST, 'tax_input', array() ), 'sp_venue', array() ) );
if ( empty( $venues ) ) {