Ich arbeite an einer WordPress -Site mit dem SportSpress -Plugin und dem WPForms. Ich habe ein Formular mit WPForms erstellt, das Kontrollkästchen enthält, die mit allen vorhandenen Clubs besiedelt sind, und ein Dropdown-Menü für die Anzahl der Beine (1-2). Wenn das Formular eingereicht wird, wird eine Round-Robin-Liga erstellt und für die Liga Spiele erzeugt. Hier ist der relevante Teil meiner Funktionen.php: < /p>
function create_sportspress_club_for_new_user($user_id) {
// Get the user data
$user_info = get_userdata($user_id);
$username = $user_info->user_login;
$profile_picture = get_user_meta($user_id, 'profile_photo', true);
// Create a new club in SportsPress
$club_id = wp_insert_post(array(
'post_title' => $username,
'post_type' => 'sp_team',
'post_status' => 'publish',
));
if (is_wp_error($club_id)) {
return;
}
if ($club_id) {
// Set the club profile picture
if ($profile_picture) {
$attachment_id = media_sideload_image($profile_picture, $club_id, null, 'id');
if (!is_wp_error($attachment_id)) {
set_post_thumbnail($club_id, $attachment_id);
}
}
// Assign the club to the user
update_user_meta($user_id, 'sp_team', $club_id);
// Assign the user to the club in SportsPress settings
update_post_meta($club_id, 'sp_team_manager', $user_id);
// Ensure the user is added to the correct taxonomy terms if needed
wp_set_object_terms($club_id, $user_id, 'sp_team_manager');
// Add the new club to the sportspress_league_menu_teams option
$teams = get_option('sportspress_league_menu_teams', array());
if (!is_array($teams)) {
$teams = array();
}
$teams[] = $club_id;
update_option('sportspress_league_menu_teams', $teams);
}
}
function create_matches_for_schedule($schedule) {
foreach ($schedule as $match) {
$home_club_id = intval($match[0]);
$away_club_id = intval($match[1]);
// Debugging: Log the IDs being used and their types
error_log("Home Club ID: $home_club_id (Type: " . gettype($home_club_id) . "), Away Club ID: $away_club_id (Type: " . gettype($away_club_id) . ")");
// Ensure the IDs are integers
if (!is_int($home_club_id) || !is_int($away_club_id)) {
error_log("Error: Club IDs are not integers. Home Club ID: $home_club_id, Away Club ID: $away_club_id");
continue;
}
// Fetch team names using their IDs
$home_club_name = get_the_title($home_club_id);
$away_club_name = get_the_title($away_club_id);
// Debugging: Ensure club names are correct
error_log("Home Club Name: $home_club_name, Away Club Name: $away_club_name");
// Check if the club names are valid
if (empty($home_club_name) || empty($away_club_name)) {
error_log("Error: Invalid club names. Home Club Name: $home_club_name, Away Club Name: $away_club_name");
continue;
}
// Create a new match in SportsPress
$match_id = wp_insert_post(array(
'post_title' => "$home_club_name vs $away_club_name",
'post_type' => 'sp_event',
'post_status' => 'publish',
'meta_input' => array(
'sp_team_home' => $home_club_id,
'sp_team_away' => $away_club_id,
),
));
}
}
< /code>
Hier ist mein Debugg.log: < /p>
[24-Jan-2025 07:17:59 UTC] Selected clubs: Array
(
[0] => mika
[1] => Yoyo FC
)
[24-Jan-2025 07:17:59 UTC] Number of legs: 1
[24-Jan-2025 07:17:59 UTC] Club IDs: Array
(
[0] => 1080
[1] => 329
)
[24-Jan-2025 07:17:59 UTC] Generated schedule: Array
(
[0] => Array
(
[0] => 1080
[1] => 329
)
)
[24-Jan-2025 07:17:59 UTC] Home Club ID: 1080 (Type: integer), Away Club ID: 329 (Type: integer)
[24-Jan-2025 07:17:59 UTC] Home Club Name: mika, Away Club Name: Yoyo FC
Die Formularübermittlung löst eine Funktion zum Erstellen von Spielen für die Liga aus. Das Problem besteht jedoch darin, dass der Vereinsbereich des „x vs y“-Spiels leer ist, obwohl ich die Vereine manuell über die wp-admin-Benutzeroberfläche zuweisen kann.
Wie kann ich Änderungen vornehmen? die Funktion, die ausgewählten Vereine automatisch den Spielen zuzuordnen, wenn sie erstellt werden?
Für Hinweise oder Vorschläge wären wir sehr dankbar. Danke!
Ich arbeite an einer WordPress -Site mit dem SportSpress -Plugin und dem WPForms. Ich habe ein Formular mit WPForms erstellt, das Kontrollkästchen enthält, die mit allen vorhandenen Clubs besiedelt sind, und ein Dropdown-Menü für die Anzahl der Beine (1-2). Wenn das Formular eingereicht wird, wird eine Round-Robin-Liga erstellt und für die Liga Spiele erzeugt. Hier ist der relevante Teil meiner Funktionen.php: < /p> [code] function create_sportspress_club_for_new_user($user_id) { // Get the user data $user_info = get_userdata($user_id); $username = $user_info->user_login; $profile_picture = get_user_meta($user_id, 'profile_photo', true);
// Create a new club in SportsPress $club_id = wp_insert_post(array( 'post_title' => $username, 'post_type' => 'sp_team', 'post_status' => 'publish', ));
if (is_wp_error($club_id)) { return; }
if ($club_id) { // Set the club profile picture if ($profile_picture) { $attachment_id = media_sideload_image($profile_picture, $club_id, null, 'id'); if (!is_wp_error($attachment_id)) { set_post_thumbnail($club_id, $attachment_id); } } // Assign the club to the user update_user_meta($user_id, 'sp_team', $club_id);
// Assign the user to the club in SportsPress settings update_post_meta($club_id, 'sp_team_manager', $user_id);
// Ensure the user is added to the correct taxonomy terms if needed wp_set_object_terms($club_id, $user_id, 'sp_team_manager');
// Add the new club to the sportspress_league_menu_teams option $teams = get_option('sportspress_league_menu_teams', array()); if (!is_array($teams)) { $teams = array(); } $teams[] = $club_id; update_option('sportspress_league_menu_teams', $teams); } }
function create_matches_for_schedule($schedule) { foreach ($schedule as $match) { $home_club_id = intval($match[0]); $away_club_id = intval($match[1]);
// Debugging: Log the IDs being used and their types error_log("Home Club ID: $home_club_id (Type: " . gettype($home_club_id) . "), Away Club ID: $away_club_id (Type: " . gettype($away_club_id) . ")");
// Ensure the IDs are integers if (!is_int($home_club_id) || !is_int($away_club_id)) { error_log("Error: Club IDs are not integers. Home Club ID: $home_club_id, Away Club ID: $away_club_id"); continue; }
// Fetch team names using their IDs $home_club_name = get_the_title($home_club_id); $away_club_name = get_the_title($away_club_id);
// Debugging: Ensure club names are correct error_log("Home Club Name: $home_club_name, Away Club Name: $away_club_name");
// Check if the club names are valid if (empty($home_club_name) || empty($away_club_name)) { error_log("Error: Invalid club names. Home Club Name: $home_club_name, Away Club Name: $away_club_name"); continue; }
// Create a new match in SportsPress $match_id = wp_insert_post(array( 'post_title' => "$home_club_name vs $away_club_name", 'post_type' => 'sp_event', 'post_status' => 'publish', 'meta_input' => array( 'sp_team_home' => $home_club_id, 'sp_team_away' => $away_club_id, ), )); } } < /code> Hier ist mein Debugg.log: < /p> [24-Jan-2025 07:17:59 UTC] Selected clubs: Array ( [0] => mika [1] => Yoyo FC )
[24-Jan-2025 07:17:59 UTC] Number of legs: 1 [24-Jan-2025 07:17:59 UTC] Club IDs: Array ( [0] => 1080 [1] => 329 )
[24-Jan-2025 07:17:59 UTC] Home Club ID: 1080 (Type: integer), Away Club ID: 329 (Type: integer) [24-Jan-2025 07:17:59 UTC] Home Club Name: mika, Away Club Name: Yoyo FC
[/code] Die Formularübermittlung löst eine Funktion zum Erstellen von Spielen für die Liga aus. Das Problem besteht jedoch darin, dass der Vereinsbereich des „x vs y“-Spiels leer ist, obwohl ich die Vereine manuell über die wp-admin-Benutzeroberfläche zuweisen kann. Wie kann ich Änderungen vornehmen? die Funktion, die ausgewählten Vereine automatisch den Spielen zuzuordnen, wenn sie erstellt werden? Für Hinweise oder Vorschläge wären wir sehr dankbar. Danke!
Ich führe eine einfache Vorlage für mich aus, aber für das Leben von mir kann ich immer noch nicht herausfinden, warum ich keine korrekten Übereinstimmungen bekomme. Ich habe es auch mit einem...
Ich implementiere Hibernate -Suche 6 in meiner Spring -Boot -Anwendung. Ich brauche die Fähigkeit, nach teilweisen Übereinstimmungen zu suchen, ähnlich wie % wie % in SQL. Aus der Dokumentation und...
Ich implementiere Hibernate -Suche 6 in meiner Spring -Boot -Anwendung. Ich brauche die Fähigkeit, nach teilweisen Übereinstimmungen zu suchen, ähnlich wie % wie % in SQL. Aus der Dokumentation und...
Ich verwende PDF.js, um PDFs in meinem React -Projekt anzuzeigen. Ich habe eine Suchleiste implementiert, mit der Benutzer innerhalb der PDF nach Text suchen können. Ich möchte jedoch die nächsten...