Automatically select venue based on home team

This commit is contained in:
Brian Miyaji
2014-10-29 19:17:46 +11:00
parent d64af09856
commit 26edb65bea
2 changed files with 56 additions and 27 deletions

View File

@@ -29,27 +29,34 @@ class SP_Meta_Box_Event_Details {
<?php _e( 'mins', 'sportspress' ); ?>
</p>
</div>
<?php foreach ( $taxonomies as $taxonomy => $post_type ): $obj = get_taxonomy( $taxonomy ); if ( $obj ): ?>
<div class="sp-event-<?php echo $taxonomy; ?>-field">
<p><strong><?php echo $obj->labels->singular_name; ?></strong></p>
<p>
<?php
$args = array(
'taxonomy' => $taxonomy,
'name' => $taxonomy,
'class' => 'sp-has-dummy',
'selected' => sp_get_the_term_id( $post->ID, $taxonomy, 0 ),
'values' => 'term_id',
'show_option_none' => __( '-- Not set --', 'sportspress' ),
);
if ( ! sp_dropdown_taxonomies( $args ) ):
sp_taxonomy_adder( $taxonomy, $post_type, $obj->labels->add_new_item );
endif;
?>
</p>
</div>
<?php endif; endforeach; ?>
<?php
foreach ( $taxonomies as $taxonomy => $post_type ) {
$obj = get_taxonomy( $taxonomy ); if ( $obj ) {
?>
<div class="sp-event-<?php echo $taxonomy; ?>-field">
<p><strong><?php echo $obj->labels->singular_name; ?></strong></p>
<p>
<?php
$args = array(
'taxonomy' => $taxonomy,
'name' => $taxonomy,
'class' => 'sp-has-dummy',
'selected' => sp_get_the_term_id_or_meta( $post->ID, $taxonomy ),
'values' => 'term_id',
'show_option_none' => __( '-- Not set --', 'sportspress' ),
);
if ( in_array( $taxonomy, apply_filters( 'sportspress_event_auto_taxonomies', array( 'sp_venue' ) ) ) ) {
$args['show_option_all'] = __( '(Auto)', 'sportspress' );
}
if ( ! sp_dropdown_taxonomies( $args ) ) {
sp_taxonomy_adder( $taxonomy, $post_type, $obj->labels->add_new_item );
}
?>
</p>
</div>
<?php
}
}
}
/**
@@ -58,8 +65,15 @@ class SP_Meta_Box_Event_Details {
public static function save( $post_id, $post ) {
update_post_meta( $post_id, 'sp_minutes', sp_array_value( $_POST, 'sp_minutes', get_option( 'sportspress_event_minutes', 90 ) ) );
$taxonomies = apply_filters( 'sportspress_event_taxonomies', array( 'sp_league' => null, 'sp_season' => null, 'sp_venue' => 'sp_event' ) );
foreach ( $taxonomies as $taxonomy => $post_type ):
wp_set_post_terms( $post_id, sp_array_value( $_POST, $taxonomy, -1 ), $taxonomy );
endforeach;
foreach ( $taxonomies as $taxonomy => $post_type ) {
$value = sp_array_value( $_POST, $taxonomy, -1 );
if ( 0 == $value) {
$teams = sp_array_value( $_POST, 'sp_team', array() );
$team = reset( $teams );
$value = sp_get_the_term_id( $team, $taxonomy );
}
wp_set_post_terms( $post_id, $value, $taxonomy );
update_post_meta( $post_id, $taxonomy, $value );
}
}
}
}