diff --git a/includes/admin/post-types/class-sp-admin-cpt-event.php b/includes/admin/post-types/class-sp-admin-cpt-event.php index 243dc75b..40deaa9d 100644 --- a/includes/admin/post-types/class-sp-admin-cpt-event.php +++ b/includes/admin/post-types/class-sp-admin-cpt-event.php @@ -66,13 +66,22 @@ class SP_Admin_CPT_Event extends SP_Admin_CPT { public function wp_insert_post_data( $data, $postarr ) { if ( $data['post_type'] == 'sp_event' && $data['post_title'] == '' ): - $teams = sp_array_value( $postarr, 'sp_team', array() ); + if ( 'teams' == get_option( 'sportspress_mode', 'teams' ) ) $post_type = 'sp_team'; + else $post_type = 'sp_player'; + + $teams = sp_array_value( $postarr, $post_type, array() ); + $teams = array_filter( $teams ); $team_names = array(); - foreach( $teams as $team ): - $team_names[] = get_the_title( $team ); + foreach ( $teams as $team ): + while ( is_array( $team ) ) { + $team = array_shift( array_filter( $team ) ); + } + if ( $team ) $team_names[] = get_the_title( $team ); endforeach; + $team_names = array_unique( $team_names ); + $data['post_title'] = implode( ' ' . get_option( 'sportspress_event_teams_delimiter', 'vs' ) . ' ', $team_names ); endif;