• Resolved ozgurgedikli

    (@ozgurgedikli)


    I am trying to show the matches in a different marquee text toner in the Alchemists theme. However, I am not getting the score information. Does anyone have any ideas?
    Where am I going wrong

    Match day range filter is filtered as 4 days before and after OK
    Match published – scheduled information OK
    Match date and time information OK
    Getting the match score is UNABLE

    Display with shortcode [matches_ticker title=”Matches” posts_per_page=”50″]

    Match Published <marquee> 2.League: September 8, 2024 Team1 4 – 3 Team2
    Match Scheduled <marquee> 2.League: September 11, 2024 Team2 vs Team1 18:30

    <?php
    // Shortcode attributes
    $atts = vc_map_get_attributes( $this->getShortcode(), $atts );
    extract( $atts );

    // Set class for marquee wrapper
    $css_class = 'marquee-wrapper' . vc_shortcode_custom_css_class( $css, ' ' ) . $this->getExtraClass( $el_class );

    // Query SportPress events (matches)
    $args = array(
    'post_type' => 'sp_event',
    'post_status' => array( 'publish', 'future' ),
    'posts_per_page' => 10,
    'date_query' => array(
    array(
    'after' => date('Y-m-d', strtotime('-4 days')), // 4 gün ?nce
    'before' => date('Y-m-d', strtotime('+4 days')), // 4 gün sonras?
    'inclusive' => true,
    'type' => 'DATE',
    ),
    ),
    );

    $events_query = new WP_Query($args);
    ?>

    <!-- Matches Ticker -->
    <div class="<?php echo esc_attr($css_class); ?>">
    <div class="container">

    <?php if ( ! empty( $title ) ) : ?>
    <div class="marquee-label">
    <?php echo esc_html( $title ); ?>
    </div>
    <?php endif; ?>

    <?php if ( $events_query->have_posts() ) : ?>
    <div class="marquee" data-gap="10" data-duplicated="false">
    <ul class="posts posts--inline">
    <?php
    $is_first_item = true; // ?lk eleman? kontrol etmek i?in bir de?i?ken olu?turuyoruz.
    while ( $events_query->have_posts() ) : $events_query->the_post(); ?>
    <?php
    // Event ID'yi al
    $event_id = get_the_ID();

    // Tak?m bilgilerini alal?m
    $teams = sp_get_teams($event_id); // Tak?mlar?n ID'lerini al

    if (is_array($teams) && count($teams) > 1) {
    // Tak?m 1 ve Tak?m 2 bilgilerini al
    $team1_id = $teams[0];
    $team2_id = $teams[1];

    // Tak?m isimlerini ?ek
    $team1_name = get_the_title($team1_id);
    $team2_name = get_the_title($team2_id);
    } else {
    // E?er tak?mlar eksikse varsay?lan "Bilinmiyor"
    $team1_name = $team2_name = 'Bilinmiyor';
    }

    // Ma? skoru alal?m (ana sonu?lar? almak i?in sp_get_main_results kullan?yoruz)
    $main_results = sp_get_main_results( $event_id );

    // Skorlar? kontrol et
    $home_score = isset($main_results['home']['goals']) ? $main_results['home']['goals'] : null;
    $away_score = isset($main_results['away']['goals']) ? $main_results['away']['goals'] : null;

    // E?er skorlar bo? ise, outcome verisini kontrol edelim
    if ($home_score === null || $away_score === null) {
    // Outcome'? alal?m
    $outcome = get_post_meta($event_id, 'sp_outcome', true);

    // Outcome verisi varsa, sonucu "Galibiyet" "Ma?lubiyet" veya "Beraberlik" olarak g?ster
    if (!empty($outcome)) {
    if ($outcome == 'win') {
    $home_score = 'Galibiyet';
    $away_score = '';
    } elseif ($outcome == 'loss') {
    $home_score = 'Ma?lubiyet';
    $away_score = '';
    } elseif ($outcome == 'draw') {
    $home_score = 'Beraberlik';
    $away_score = '';
    } else {
    $home_score = $away_score = 'Bilinmiyor';
    }
    } else {
    $home_score = $away_score = 'Bilinmiyor';
    }
    }

    // Ma? saati UTC+3 olarak ayarlanacak
    $match_time_utc = get_post_time( 'H:i', true, $event_id );
    $match_time_utc3 = strtotime($match_time_utc) + (3 * 3600); // 3 saat ekleyerek UTC+3 yap?yoruz

    // Formatl? saat UTC+3'e g?re
    $formatted_time = !empty($match_time_utc) ? date('H:i', $match_time_utc3) : 'Bilinmiyor';

    // Ma? tarihi
    $date_html = get_post_time( 'Y-m-d', false, $event_id );

    // Ma? tarihi varsa formatla, yoksa "Bilinmiyor" kullan
    $formatted_date = !empty($date_html) ? date_i18n('j F Y', strtotime($date_html)) : 'Bilinmiyor'; // Türk?e tarih format?

    // Lig ad?
    $leagues = wp_get_post_terms($event_id, 'sp_league', array('fields' => 'names'));
    $league_name = !empty($leagues) ? $leagues[0] : 'Lig Bilinmiyor';

    // Ma??n durumu: Yay?nlanm?? m?, gelecekte mi?
    $post_status = get_post_status($event_id);

    // ?u anki zaman? alal?m
    $current_time = current_time('Y-m-d H:i');

    // Ge?mi? Ma? Kontrolü: Oynam?? ma?lar? ve skorlar? ay?ral?m
    if ($post_status == 'publish' && !empty($home_score) && !empty($away_score) && $date_html < date('Y-m-d')) {
    // Ge?mi? ma? ise sonu?lar? g?ster
    $match_text = esc_html($formatted_date . ' - ' . $team1_name . ' ' . $home_score . ' - ' . $away_score . ' ' . $team2_name);
    }
    // E?er ma? bugünün tarihine sahip ve saat ?u anki saatten daha sonraysa (yani oynanmam??sa)
    elseif ($post_status == 'publish' && ($date_html == date('Y-m-d')) && ($match_time_utc3 > strtotime($current_time))) {
    $match_text = esc_html($formatted_date . ' - ' . $team1_name . ' vs ' . $team2_name . ' - ' . $formatted_time);
    }
    // E?er ma? ge?mi?te oynanm??sa ve skoru eksikse, outcome ile durumu g?ster
    elseif ( $post_status == 'publish' && ($date_html < date('Y-m-d')) && (empty($home_score) || empty($away_score)) ) {
    $outcome = get_post_meta($event_id, 'sp_outcome', true);
    if ($outcome == 'win') {
    $home_score = 'Galibiyet';
    $away_score = '';
    } elseif ($outcome == 'loss') {
    $home_score = 'Ma?lubiyet';
    $away_score = '';
    } elseif ($outcome == 'draw') {
    $home_score = 'Beraberlik';
    $away_score = '';
    }
    $match_text = esc_html($formatted_date . ' - ' . $team1_name . ' ' . $home_score . ' - ' . $away_score . ' ' . $team2_name);
    }
    // Gelecek ma?lar: Tarih ve saat ile g?ster
    elseif ( $post_status == 'future' || $date_html > date('Y-m-d') ) {
    // Gelecek ma?sa "vs" ve saat g?ster
    $match_text = esc_html($formatted_date . ' - ' . $team1_name . ' vs ' . $team2_name . ' - ' . $formatted_time);
    }
    // Di?er durumlar i?in "Bilinmiyor"
    else {
    $match_text = esc_html($formatted_date . ' - ' . $team1_name . ' vs ' . $team2_name . ' Bilinmiyor');
    }

    // Separator ekleme i?lemi
    if ( !$is_first_item ) {
    echo '<li class="posts__item separator"> | </li>'; // Separator? burada ekliyoruz.
    }
    $is_first_item = false; // ?lk eleman art?k i?lendi.
    ?>

    <!-- Match item -->
    <li class="posts__item">
    <h6 class="posts__title">
    <?php echo esc_html($league_name . ':'); ?> <!-- League name -->
    </h6>
    <p class="posts__text">
    <?php echo esc_html($match_text); ?> <!-- Match details -->
    </p>
    </li>
    <?php endwhile; ?>
    </ul>
    </div><!-- .marquee -->
    <?php wp_reset_postdata(); ?>
    <?php endif; ?>

    </div>
    </div>
    <!-- Matches Ticker / End -->
    • This topic was modified 1 month, 1 week ago by ozgurgedikli.
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor Savvas

    (@savvasha)

    Hi there @ozgurgedikli,

    As I can see from your code, you are using the following code to get your results:

    $main_results = sp_get_main_results( $event_id );

    $home_score = isset($main_results['home']['goals']) ? $main_results['home']['goals'] : null;
    $away_score = isset($main_results['away']['goals']) ? $main_results['away']['goals'] : null;$main_results = sp_get_main_results( $event_id );

    Are you sure that the $main_results array has the structure you are trying to use?

    Thanks,
    Savvas

    Thread Starter ozgurgedikli

    (@ozgurgedikli)

    Yes @savvasha ,

    That was during an experiment, I tried to capture the results like this, but it didn’t work.
    I tried this first but didn’t get any results

    thanks

    $event_id = get_the_ID();
    $home_score = get_post_meta( $event_id, 'sp_results_home', true );
    $away_score = get_post_meta( $event_id, 'sp_results_away', true );
    Plugin Contributor Savvas

    (@savvasha)

    Hi there @ozgurgedikli ,

    If you are using AI to help you on the code, have in mind that AI sometimes uses post_meta keys and functions that are not actually correct or real. For example, there is no sp_results_home or sp_results_awaypost_meta keys anywhere in SportsPress code.

    Try something like the following:

    $main_results = sp_get_main_results( $event_id );

    $home_score = isset($main_results[0]) ? $main_results[0] : null;
    $away_score = isset($main_results[1]) ? $main_results[1] : null;

    sp_get_main_results() function returns a simple array with just the values of your primary result (in your example “goals”)

    Thanks,
    Savvas

    Thread Starter ozgurgedikli

    (@ozgurgedikli)

    Thanks @savvasha

    With debugging I see that I can now pull the data in. However, I see that I am making errors during marquee printing.

    [10-Oct-2024 20:28:56 UTC] PHP Notice:  Undefined offset: 0 in /home/duzceama/public_html/wp-includes/meta.php on line 638
    [10-Oct-2024 20:28:57 UTC] Team 1: Tak?m2, Team 2: Tak?m1
    [10-Oct-2024 20:28:57 UTC] Main Results: Array
    (
    )

    [10-Oct-2024 20:28:57 UTC] Home Score: Bilinmiyor, Away Score: Bilinmiyor
    [10-Oct-2024 20:28:57 UTC] Match Time (UTC+3): 18:30
    [10-Oct-2024 20:28:57 UTC] League Name: 2.Amat?r Lig (Play-Off)
    [10-Oct-2024 20:28:57 UTC] Post Status for Event ID 22210: publish
    [10-Oct-2024 20:28:57 UTC] Team 1: Tak?m1, Team 2: Tak?m2
    [10-Oct-2024 20:28:57 UTC] Main Results: Array
    (
    [0] => 12
    [1] => 8
    )

    [10-Oct-2024 20:28:57 UTC] Home Score: 12, Away Score: 8
    [10-Oct-2024 20:28:57 UTC] Match Time (UTC+3): 12:30
    [10-Oct-2024 20:28:57 UTC] League Name: 2.Amat?r Lig (Play-Off)
    [10-Oct-2024 20:28:57 UTC] Post Status for Event ID 22209: publish
    [10-Oct-2024 20:28:57 UTC] PHP Notice: ob_end_flush(): failed to send buffer of zlib output compression (0) in /home/duzceama/public_html/wp-includes/functions.php on line 5427
    Plugin Contributor Savvas

    (@savvasha)

    Hi there @ozgurgedikli ,

    From your error log I cannot say what exactly is the problem. In general, before getting the value of something inside an array, you should first check if it is set (with isset() function) like below:

    $home_score = isset($main_results[0]) ? $main_results[0] : null;

    Thanks,
    Savvas

    Thread Starter ozgurgedikli

    (@ozgurgedikli)

    Code errors were corrected, maquee printing was perfect. I completed the played matches, SCORES, and the matches to be played, by giving them color and style in the form of a program. I used Alchemists as Marguee general css data.

    I shared the codes to make it a nice share for Sportspress users.

    Marquee output ==> SKORLAR:10 Ekim 2024 => 2.Amat?r Lig (Play-Off): Tak?m1 12 – 8 Tak?m2 | PROGRAM:11 Ekim 2024 => 2.Amat?r Lig (Play-Off): Tak?m2 vs Tak?m1 – 18:30

    https://ibb.co/Tckt7ck

    Display with shortcode [matches_ticker title=”Matches” posts_per_page=”50″]
    <?php
    // Shortcode attributes
    $atts = vc_map_get_attributes($this->getShortcode(), $atts);
    extract($atts);

    // Set class for marquee wrapper
    $css_class = isset($css) ? 'marquee-wrapper ' . vc_shortcode_custom_css_class($css, ' ') : 'marquee-wrapper';
    $css_class .= isset($el_class) ? $this->getExtraClass($el_class) : '';

    // Query SportPress events (matches)
    $args = array(
    'post_type' => 'sp_event',
    'post_status' => array('publish', 'future'),
    'posts_per_page' => 10,
    'date_query' => array(
    array(
    'after' => date('Y-m-d', strtotime('-4 days')), // 4 gün ?nce
    'before' => date('Y-m-d', strtotime('+4 days')), // 4 gün sonras?
    'inclusive' => true,
    'type' => 'DATE',
    ),
    ),
    );

    $events_query = new WP_Query($args);

    $completed_matches = [];
    $upcoming_matches = [];
    ?>

    <!-- Matches Ticker -->
    <div class="<?php echo esc_attr($css_class); ?>">
    <div class="container">

    <?php if (!empty($title)) : ?>
    <div class="marquee-label">
    <?php echo esc_html($title); ?>
    </div>
    <?php endif; ?>

    <div class="marquee" data-gap="10" data-duplicated="false">
    <ul class="posts posts--inline">
    <?php if ($events_query->have_posts()) : ?>
    <?php
    while ($events_query->have_posts()) : $events_query->the_post();
    $event_id = get_the_ID();

    // Tak?mlar?n ID'lerini al
    $teams = sp_get_teams($event_id);

    if (is_array($teams) && count($teams) > 1) {
    $team1_id = $teams[0];
    $team2_id = $teams[1];

    $team1_name = get_the_title($team1_id);
    $team2_name = get_the_title($team2_id);
    } else {
    // Tak?mlar eksikse "Bilinmiyor" olarak ayarl?yoruz
    $team1_name = $team2_name = 'Bilinmiyor';
    }

    // Ma? skoru alal?m
    $main_results = sp_get_main_results( $event_id );

    if (!empty($main_results) && count($main_results) >= 2) {
    $home_score = $main_results[0];
    $away_score = $main_results[1];
    } else {
    $home_score = 'Bilinmiyor';
    $away_score = 'Bilinmiyor';
    }

    // UTC+3 saat dilimine g?re ma? saati
    $match_time_utc = get_post_time('H:i', true, $event_id);
    $match_time_utc3 = strtotime($match_time_utc) + (3 * 3600); // UTC+3
    $formatted_time = !empty($match_time_utc) ? date('H:i', $match_time_utc3) : 'Bilinmiyor';

    // Lig ad?
    $leagues = wp_get_post_terms($event_id, 'sp_league', array('fields' => 'names'));
    $league_name = !empty($leagues) ? $leagues[0] : 'Lig Bilinmiyor';

    // Ma? tarihi
    $date_html = get_post_time('Y-m-d', false, $event_id);
    $formatted_date = !empty($date_html) ? date_i18n('j F Y', strtotime($date_html)) : 'Bilinmiyor';

    // Ma??n durumu: Yay?nlanm?? m??
    $post_status = get_post_status($event_id);
    $current_time = current_time('Y-m-d H:i');

    if ($post_status == 'publish' && !empty($home_score) && !empty($away_score) && $date_html < date('Y-m-d')) {
    // Completed matches
    $completed_matches[] = '<span style="color:#3904dd;">' . esc_html($formatted_date . ' => ' . $league_name . ': ' . $team1_name . ' ' . $home_score . ' - ' . $away_score . ' ' . $team2_name) . '</span>';
    } elseif ($post_status == 'future' || ($date_html >= date('Y-m-d') && $match_time_utc3 > strtotime($current_time))) {
    // Upcoming matches
    $upcoming_matches[] = '<span style="color:#ff0404;">' . esc_html($formatted_date . ' => ' . $league_name . ': ' . $team1_name . ' vs ' . $team2_name . ' - ' . $formatted_time) . '</span>';
    } else {
    $upcoming_matches[] = '<span style="color:#ff0404;">' . esc_html($formatted_date . ' => ' . $league_name . ': ' . $team1_name . ' vs ' . $team2_name . ' Bilinmiyor') . '</span>';
    }
    endwhile;
    ?>

    <!-- Display completed matches -->
    <?php if (!empty($completed_matches)) : ?>
    <li class="posts__item">
    <h6 class="posts__title">SKORLAR:</h6>
    <p class="posts__text">
    <?php echo implode(' | ', $completed_matches); ?>
    </p>
    </li>
    <?php endif; ?>

    <!-- Display upcoming matches -->
    <?php if (!empty($upcoming_matches)) : ?>
    <li class="posts__item">
    <h6 class="posts__title">PROGRAM:</h6>
    <p class="posts__text">
    <?php echo implode(' | ', $upcoming_matches); ?>
    </p>
    </li>
    <?php endif; ?>

    <?php else : ?>
    <!-- If no matches are available, show this message inside the marquee -->
    <li class="posts__item">
    <p class="posts__text">HAFTALIK MüSABAKALAR YAYINLANMADI</p>
    </li>
    <?php endif; ?>
    </ul>
    </div><!-- .marquee -->
    <?php wp_reset_postdata(); ?>

    </div>
    </div>
    <!-- Matches Ticker / End -->
    • This reply was modified 1 month, 1 week ago by ozgurgedikli.
    Plugin Contributor Savvas

    (@savvasha)

    Great work @ozgurgedikli and thanks for sharing your final code !!!

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.