Sportspress match scores pull
-
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 wrongMatch 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 UNABLEDisplay 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 -->
Viewing 7 replies - 1 through 7 (of 7 total)
Viewing 7 replies - 1 through 7 (of 7 total)
- You must be logged in to reply to this topic.