Incontri e risultati

term_id;
};

// Helper per trovare o creare le squadre (post_type: sp_team)
$get_or_create_team = function( $team_name ) {
$query = new WP_Query( array(
‘post_type’ => ‘sp_team’,
‘title’ => $team_name,
‘posts_per_page’ => 1,
‘post_status’ => ‘publish’
) );
if ( $query->have_posts() ) {
return $query->posts[0]->ID;
}
return wp_insert_post( array(
‘post_title’ => $team_name,
‘post_type’ => ‘sp_team’,
‘post_status’ => ‘publish’
) );
};

$season_id = $get_or_create_term( $season_name, ‘sp_season’ );
$league_id = $get_or_create_term( $league_name, ‘sp_league’ );

// Lista completa delle 22 giornate estratte dalle immagini
$matches = array(
// Ottobre 2026
array( ‘day’ => ‘1 GIORNATA ANDATA’, ‘date’ => ‘2026-10-18 18:30:00’, ‘home’ => true, ‘opponent’ => ‘CRATICAM VOLLEY ACADEMY’ ),
array( ‘day’ => ‘2 GIORNATA ANDATA’, ‘date’ => ‘2026-10-24 16:00:00’, ‘home’ => false, ‘opponent’ => ‘PINK VOLO LAMEZIA’ ),
// Novembre 2026
array( ‘day’ => ‘3 GIORNATA ANDATA’, ‘date’ => ‘2026-11-01 18:30:00’, ‘home’ => false, ‘opponent’ => ‘TOP VOLLEY LAMEZIA’ ),
array( ‘day’ => ‘4 GIORNATA ANDATA’, ‘date’ => ‘2026-11-08 18:30:00’, ‘home’ => true, ‘opponent’ => ‘RAFFAELE & ARPAIA LAMEZIA’ ),
array( ‘day’ => ‘5 GIORNATA ANDATA’, ‘date’ => ‘2026-11-14 18:00:00’, ‘home’ => false, ‘opponent’ => ‘AVOLIO-NOVA VOLLEY’ ),
array( ‘day’ => ‘6 GIORNATA ANDATA’, ‘date’ => ‘2026-11-22 18:30:00’, ‘home’ => true, ‘opponent’ => ‘VOLLEY ROGLIANO’ ),
array( ‘day’ => ‘7 GIORNATA ANDATA’, ‘date’ => ‘2026-11-28 18:30:00’, ‘home’ => false, ‘opponent’ => ‘PALLAVOLO PAOLA’ ),
// Dicembre 2026
array( ‘day’ => ‘8 GIORNATA ANDATA’, ‘date’ => ‘2026-12-06 18:30:00’, ‘home’ => true, ‘opponent’ => ‘CROTONE’ ),
array( ‘day’ => ‘9 GIORNATA ANDATA’, ‘date’ => ‘2026-12-13 17:30:00’, ‘home’ => false, ‘opponent’ => ‘SPES PRAIA VOLLEY’ ),
array( ‘day’ => ’10 GIORNATA ANDATA’, ‘date’ => ‘2026-12-16 18:30:00’, ‘home’ => true, ‘opponent’ => ‘SPORTING MAGNA GRECIA’ ),
array( ‘day’ => ’11 GIORNATA ANDATA’, ‘date’ => ‘2026-12-20 17:00:00’, ‘home’ => false, ‘opponent’ => ‘SILAN VOLLEY’ ),
// Gennaio 2027
array( ‘day’ => ’12 GIORNATA RITORNO’, ‘date’ => ‘2027-01-17 18:30:00’, ‘home’ => false, ‘opponent’ => ‘CRATICAM VOLLEY ACADEMY’ ),
array( ‘day’ => ’13 GIORNATA RITORNO’, ‘date’ => ‘2027-01-24 18:30:00’, ‘home’ => true, ‘opponent’ => ‘PINK VOLO LAMEZIA’ ),
array( ‘day’ => ’14 GIORNATA RITORNO’, ‘date’ => ‘2027-01-31 18:30:00’, ‘home’ => true, ‘opponent’ => ‘TOP VOLLEY LAMEZIA’ ),
// Febbraio 2027
array( ‘day’ => ’15 GIORNATA RITORNO’, ‘date’ => ‘2027-02-06 19:30:00’, ‘home’ => false, ‘opponent’ => ‘RAFFAELE & ARPAIA LAMEZIA’ ),
array( ‘day’ => ’16 GIORNATA RITORNO’, ‘date’ => ‘2027-02-14 18:30:00’, ‘home’ => true, ‘opponent’ => ‘AVOLIO-NOVA VOLLEY’ ),
array( ‘day’ => ’17 GIORNATA RITORNO’, ‘date’ => ‘2027-02-21 18:00:00’, ‘home’ => false, ‘opponent’ => ‘VOLLEY ROGLIANO’ ),
array( ‘day’ => ’18 GIORNATA RITORNO’, ‘date’ => ‘2027-02-28 18:30:00’, ‘home’ => true, ‘opponent’ => ‘PALLAVOLO PAOLA’ ),
// Marzo 2027
array( ‘day’ => ’19 GIORNATA RITORNO’, ‘date’ => ‘2027-03-06 18:30:00’, ‘home’ => false, ‘opponent’ => ‘CROTONE’ ),
array( ‘day’ => ’20 GIORNATA RITORNO’, ‘date’ => ‘2027-03-14 18:30:00’, ‘home’ => true, ‘opponent’ => ‘SPES PRAIA VOLLEY’ ),
array( ‘day’ => ’21 GIORNATA RITORNO’, ‘date’ => ‘2027-03-21 18:30:00’, ‘home’ => false, ‘opponent’ => ‘SPORTING MAGNA GRECIA’ ),
array( ‘day’ => ’22 GIORNATA RITORNO’, ‘date’ => ‘2027-03-24 18:30:00’, ‘home’ => true, ‘opponent’ => ‘SILAN VOLLEY’ ),
);

$created_count = 0;

foreach ( $matches as $m ) {
$home_team_name = $m[‘home’] ? $main_team : $m[‘opponent’];
$away_team_name = $m[‘home’] ? $m[‘opponent’] : $main_team;

$home_id = $get_or_create_team( $home_team_name );
$away_id = $get_or_create_team( $away_team_name );

$event_title = “{$home_team_name} vs {$away_team_name}”;

// Creazione del post dell’evento
$event_data = array(
‘post_title’ => $event_title,
‘post_type’ => ‘sp_event’,
‘post_status’ => ‘publish’,
‘post_date’ => $m[‘date’],
);

$event_id = wp_insert_post( $event_data );

if ( $event_id && ! is_wp_error( $event_id ) ) {
// Assegna la squadra di casa e ospite
update_post_meta( $event_id, ‘sp_team’, array( $home_id, $away_id ) );

// Assegna la stagione e la competizione
if ( $season_id ) wp_set_object_terms( $event_id, intval( $season_id ), ‘sp_season’ );
if ( $league_id ) wp_set_object_terms( $event_id, intval( $league_id ), ‘sp_league’ );

// Memorizza la giornata
update_post_meta( $event_id, ‘sp_day’, $m[‘day’] );

$created_count++;
}
}

return “Importazione completata: {$created_count} eventi inseriti in SportsPress!”;
}

// Per eseguire l’importazione una sola volta, sblocca la riga seguente ed entra nel pannello di amministrazione:
// add_action( ‘admin_init’, function() { echo importa_calendario_sportspress_bisignano(); die(); } );

Ottobre: 2026
L M M G V S D
     
 1234
567891011
12131415161718
19202122232425
262728293031