Display events in custom calendar

This commit is contained in:
Brian Miyaji
2014-01-25 17:51:30 +11:00
parent 84233c4d8b
commit 0ef0831ec2
7 changed files with 82 additions and 61 deletions

View File

@@ -135,6 +135,21 @@ if ( !function_exists( 'sportspress_set_post_views' ) ) {
}
}
if ( !function_exists( 'sportspress_get_post_datetime' ) ) {
function sportspress_get_post_datetime( $post ) {
if ( $post->post_status == 'future' ):
$status = __( 'Scheduled', 'sportspress' );
elseif( $post->post_status == 'publish' ):
$status = __( 'Played', 'sportspress' );
elseif( $post->post_status == 'draft' ):
$status = __( 'Draft', 'sportspress' );
else:
$status = __( 'Pending Review', 'sportspress' );
endif;
return $status . '<br />' . date_i18n( __( 'M j, Y @ G:i', 'sportspress' ), strtotime( $post->post_date ) );
}
}
if ( !function_exists( 'sportspress_get_post_precision' ) ) {
function sportspress_get_post_precision( $post_id ) {
$precision = get_post_meta ( $post_id, 'sp_precision', true );
@@ -594,7 +609,7 @@ if ( !function_exists( 'sportspress_edit_calendar_table' ) ) {
?>
<tr class="sp-row sp-post<?php if ( $i % 2 == 0 ) echo ' alternate'; ?>">
<td>
<?php echo $event->post_title; ?>
<?php edit_post_link( $event->post_title, null, null, $event->ID ); ?>
</td>
<td>
<?php echo get_the_time( get_option('date_format'), $event->ID ); ?>
@@ -1161,24 +1176,6 @@ if ( !function_exists( 'sportspress_get_calendar_data' ) ) {
$seasons = get_the_terms( $post_id, 'sp_season' );
$venues = get_the_terms( $post_id, 'sp_venue' );
if ( ! $leagues || ! $seasons || ! $venues )
return array();
$league_ids = array();
foreach( $leagues as $league ):
$league_ids[] = $league->term_id;
endforeach;
$season_ids = array();
foreach( $seasons as $season ):
$season_ids[] = $season->term_id;
endforeach;
$venue_ids = array();
foreach( $venues as $venue ):
$venue_ids[] = $venue->term_id;
endforeach;
$args = array(
'post_type' => 'sp_event',
'numberposts' => -1,
@@ -1187,24 +1184,46 @@ if ( !function_exists( 'sportspress_get_calendar_data' ) ) {
'order' => 'ASC',
'post_status' => 'any',
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'sp_league',
'field' => 'id',
'terms' => $league_ids
),
array(
'taxonomy' => 'sp_season',
'field' => 'id',
'terms' => $season_ids
),
array(
'taxonomy' => 'sp_venue',
'field' => 'id',
'terms' => $venue_ids
),
'relation' => 'AND'
),
);
if ( $leagues ):
$league_ids = array();
foreach( $leagues as $league ):
$league_ids[] = $league->term_id;
endforeach;
$args['tax_query'][] = array(
'taxonomy' => 'sp_league',
'field' => 'id',
'terms' => $league_ids
);
endif;
if ( $seasons ):
$season_ids = array();
foreach( $seasons as $season ):
$season_ids[] = $season->term_id;
endforeach;
$args['tax_query'][] = array(
'taxonomy' => 'sp_season',
'field' => 'id',
'terms' => $season_ids
);
endif;
if ( $venues ):
$venue_ids = array();
foreach( $venues as $venue ):
$venue_ids[] = $venue->term_id;
endforeach;
$args['tax_query'][] = array(
'taxonomy' => 'sp_venue',
'field' => 'id',
'terms' => $venue_ids
);
endif;
$events = get_posts( $args );
return $events;