diff --git a/includes/class-sp-calendar.php b/includes/class-sp-calendar.php
index be115786..52f53372 100644
--- a/includes/class-sp-calendar.php
+++ b/includes/class-sp-calendar.php
@@ -60,9 +60,7 @@ class SP_Calendar extends SP_Custom_Post {
$this->from = get_post_meta( $this->ID, 'sp_date_from', true );
if ( ! $this->to ):
- $to = new DateTime( get_post_meta( $this->ID, 'sp_date_to', true ) );
- $to->modify( '+1 day' );
- $this->to = $to->format( 'Y-m-d' );
+ $this->to = get_post_meta( $this->ID, 'sp_date_to', true );
endif;
}
@@ -163,11 +161,12 @@ class SP_Calendar extends SP_Custom_Post {
remove_filter( 'posts_where', array( $this, 'range' ) );
return $events;
-
}
public function range( $where = '' ) {
- $where .= " AND post_date BETWEEN '" . $this->from . "' AND '" . $this->to . "'";
+ $to = new DateTime( $this->to );
+ $to->modify( '+1 day' );
+ $where .= " AND post_date BETWEEN '" . $this->from . "' AND '" . $to->format( 'Y-m-d' ) . "'";
return $where;
}
}
diff --git a/includes/class-sp-event.php b/includes/class-sp-event.php
index 6027ae5f..1e35d24c 100644
--- a/includes/class-sp-event.php
+++ b/includes/class-sp-event.php
@@ -111,6 +111,59 @@ class SP_Event extends SP_Custom_Post{
endif;
}
+ public function main_results() {
+ // Get main result option
+ $main_result = get_option( 'sportspress_main_result', null );
+
+ // Get teams from event
+ $teams = get_post_meta( $this->ID, 'sp_team', false );
+
+ // Initialize output
+ $output = array();
+
+ // Return empty array if there are no teams
+ if ( ! $teams ) return $output;
+
+ // Get results from event
+ $results = get_post_meta( $this->ID, 'sp_results', true );
+
+ // Loop through teams
+ foreach ( $teams as $team_id ) {
+
+ // Skip if not a team
+ if ( ! $team_id ) continue;
+
+ // Get team results from all results
+ $team_results = sp_array_value( $results, $team_id, null );
+
+ // Get main or last result
+ if ( $main_result ) {
+
+ // Get main result from team results
+ $team_result = sp_array_value( $team_results, $main_result, null );
+ } else {
+
+ // If there are any team results available
+ if ( is_array( $team_results ) ) {
+
+ // Get last result that is not outcome
+ unset( $team_results['outcome'] );
+ $team_result = end( $team_results );
+ } else {
+
+ // Give team null result
+ $team_result = null;
+ }
+ }
+
+ if ( null != $team_result ) {
+ $output[] = $team_result;
+ }
+ }
+
+ return $output;
+ }
+
public function lineup_filter( $v ) {
return sp_array_value( $v, 'status', 'lineup' ) == 'lineup';
}
diff --git a/includes/sp-api-functions.php b/includes/sp-api-functions.php
new file mode 100644
index 00000000..53d6c76d
--- /dev/null
+++ b/includes/sp-api-functions.php
@@ -0,0 +1,37 @@
+main_results();
+}
+
+function sp_main_results( $post = null ) {
+ $results = sp_get_main_results( $post );
+ echo implode( ' - ', $results );
+}
\ No newline at end of file
diff --git a/includes/sp-core-functions.php b/includes/sp-core-functions.php
index 9981be4d..8f425d82 100644
--- a/includes/sp-core-functions.php
+++ b/includes/sp-core-functions.php
@@ -16,6 +16,7 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
include( 'sp-conditional-functions.php' );
include( 'sp-formatting-functions.php' );
include( 'sp-deprecated-functions.php' );
+include( 'sp-api-functions.php' );
/**
* Get template part.
diff --git a/templates/event-blocks.php b/templates/event-blocks.php
index d6c7848c..0761682e 100644
--- a/templates/event-blocks.php
+++ b/templates/event-blocks.php
@@ -12,10 +12,11 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
$primary_result = get_option( 'sportspress_primary_result', null );
$defaults = array(
+ 'id' => null,
'status' => 'default',
'date' => 'default',
- 'date_to' => 'default',
'date_from' => 'default',
+ 'date_to' => 'default',
'number' => -1,
'link_teams' => get_option( 'sportspress_link_teams', 'no' ) == 'yes' ? true : false,
'paginated' => get_option( 'sportspress_event_blocks_paginated', 'yes' ) == 'yes' ? true : false,
diff --git a/templates/event-calendar.php b/templates/event-calendar.php
index d8e234c5..677d8c41 100644
--- a/templates/event-calendar.php
+++ b/templates/event-calendar.php
@@ -15,8 +15,8 @@ $defaults = array(
'id' => null,
'status' => 'default',
'date' => 'default',
- 'date_to' => 'default',
'date_from' => 'default',
+ 'date_to' => 'default',
'initial' => true,
'caption_tag' => 'h4',
'show_all_events_link' => false,
diff --git a/templates/event-list.php b/templates/event-list.php
index e93864aa..09b8b8ea 100644
--- a/templates/event-list.php
+++ b/templates/event-list.php
@@ -9,14 +9,12 @@
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
-$primary_result = get_option( 'sportspress_primary_result', null );
-
$defaults = array(
'id' => null,
'status' => 'default',
'date' => 'default',
- 'date_to' => 'default',
'date_from' => 'default',
+ 'date_to' => 'default',
'number' => -1,
'link_teams' => get_option( 'sportspress_link_teams', 'no' ) == 'yes' ? true : false,
'link_venues' => get_option( 'sportspress_link_venues', 'yes' ) == 'yes' ? true : false,
@@ -107,10 +105,10 @@ endif;
if ( isset( $limit ) && $i >= $limit ) continue;
$teams = get_post_meta( $event->ID, 'sp_team' );
- $results = get_post_meta( $event->ID, 'sp_results', true );
$video = get_post_meta( $event->ID, 'sp_video', true );
- $main_results = array();
+ $main_results = sp_get_main_results( $event );
+
$teams_output = '';
$teams_array = '';
@@ -118,27 +116,15 @@ endif;
foreach ( $teams as $team ):
$name = get_the_title( $team );
if ( $name ):
- $team_results = sp_array_value( $results, $team, null );
-
- if ( $primary_result ):
- $team_result = sp_array_value( $team_results, $primary_result, null );
- else:
- if ( is_array( $team_results ) ):
- unset( $team_results['outcome'] );
- $team_result = end( $team_results );
- else:
- $team_result = null;
- endif;
- endif;
-
if ( $link_teams ):
$team_output = '' . $name . '';
else:
$team_output = $name;
endif;
+ $team_result = sp_array_value( $main_results, $team, null );
+
if ( $team_result != null ):
- $main_results[] = $team_result;
if ( $usecolumns != null && ! in_array( 'time', $usecolumns ) ):
$team_output .= ' (' . $team_result . ')';
endif;
@@ -175,7 +161,7 @@ endif;
if ( ! empty( $main_results ) ):
echo implode( ' - ', $main_results );
else:
- echo ' ' . get_post_time( 'H:i:s', false, $event ) . '' . get_post_time( get_option( 'time_format' ), false, $event, true );
+ echo ' ' . get_post_time( 'H:i:s', false, $event ) . '' . sp_get_time( $event );
endif;
echo '';
endif;