Automatically select venue based on home team
This commit is contained in:
@@ -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 );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -298,7 +298,7 @@ if ( !function_exists( 'sp_numbers_to_words' ) ) {
|
||||
}
|
||||
|
||||
if ( !function_exists( 'sp_get_the_term_id' ) ) {
|
||||
function sp_get_the_term_id( $post_id, $taxonomy, $index ) {
|
||||
function sp_get_the_term_id( $post_id, $taxonomy ) {
|
||||
$terms = get_the_terms( $post_id, $taxonomy );
|
||||
if ( is_array( $terms ) && sizeof( $terms ) > 0 ):
|
||||
$term = reset( $terms );
|
||||
@@ -312,6 +312,21 @@ if ( !function_exists( 'sp_get_the_term_id' ) ) {
|
||||
}
|
||||
}
|
||||
|
||||
if ( !function_exists( 'sp_get_the_term_id_or_meta' ) ) {
|
||||
function sp_get_the_term_id_or_meta( $post_id, $taxonomy ) {
|
||||
$terms = get_the_terms( $post_id, $taxonomy );
|
||||
if ( is_array( $terms ) && sizeof( $terms ) > 0 ):
|
||||
$term = reset( $terms );
|
||||
if ( is_object( $term ) && property_exists( $term, 'term_id' ) )
|
||||
return $term->term_id;
|
||||
else
|
||||
return 0;
|
||||
else:
|
||||
return get_post_meta( $post_id, $taxonomy, true );
|
||||
endif;
|
||||
}
|
||||
}
|
||||
|
||||
if ( !function_exists( 'sp_get_url' ) ) {
|
||||
function sp_get_url( $post_id ) {
|
||||
$url = get_post_meta( $post_id, 'sp_url', true );
|
||||
@@ -502,10 +517,10 @@ if ( !function_exists( 'sp_dropdown_taxonomies' ) ) {
|
||||
echo '<option></option>';
|
||||
endif;
|
||||
if ( $args['show_option_all'] ):
|
||||
printf( '<option value="0">%s</option>', $args['show_option_all'] );
|
||||
printf( '<option value="0" ' . selected( '0', $selected, false ) . '>%s</option>', $args['show_option_all'] );
|
||||
endif;
|
||||
if ( $args['show_option_none'] ):
|
||||
printf( '<option value="-1">%s</option>', $args['show_option_none'] );
|
||||
printf( '<option value="-1" ' . selected( '-1', $selected, false ) . '>%s</option>', $args['show_option_none'] );
|
||||
endif;
|
||||
endif;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user