<?php
	
// Make sure we don't expose any info if called directly
if ( !function_exists( 'add_action' ) ) {
	echo 'Hi there!  I\'m just a plugin, not much I can do when called directly.';
	exit;
}
?>

<div class="day_date"><?php echo $dt->format( 'd' ); ?><?php 
	if ( $num_of_events > 0 ) { 
		echo '<span class="day_event_count">'. $num_of_events .' events' .'</span>'; 
	} else { 
		echo '<span class="day_event_count none">no events</span>'; } 
	?></div>

<?php  
	if ( isset( $groupbydate[ $full_date ] ) && !empty( $groupbydate[ $full_date ] ) ) {
		foreach( $groupbydate[ $full_date ] as $event_info ) {
		
		$tournamentsID = $event_info['ID'];
?>

<?php
	$trailvalues = get_post_meta( $tournamentsID, 'trail', true );
	$trail = '';
	//print_r($division);
	if( isset($trailvalues) && intval( $trailvalues ) > 0 ) {
		$trailpost = get_posts( array( 'p' => $trailvalues, 'post_type'=> 'trails', 'fields' => 'ids' ) );
	
		if ( !empty( $trailpost ) && intval( $trailpost[0] ) > 0 ) {

			$division= get_post_meta( $trailpost[0], 'division', true );

			$trail .=  '<a href="'.get_the_permalink( $trailpost[0] ).'" >'. titlechange( get_the_title( $trailpost[0] ) ) .'</a>';
			if ( !empty( $division ) ) {
				$trail .= " / <span style='font-weight:normal !important;'>".$division."</span>";
			}

			// /* Restore original Post Data */
			wp_reset_postdata();
		} else {
			// no posts found
		}
	}
?>
<?php  
	$lakesvalues= get_post_meta( $tournamentsID,'lake');
	$lake = '';
	if(isset($lakesvalues[0]) && is_numeric($lakesvalues[0]) && $lakesvalues[0] > 0) {
		$lakespost = new WP_Query(array( 'p' => $lakesvalues[0],'post_type'=> 'lakes' ));
		if ( $lakespost->have_posts() ) {
			while ( $lakespost->have_posts() ) {
				$lakespost->the_post();
				$lake .=  '<a href="'.get_permalink().'" >'.titlechange(get_the_title()).'</a>';
			}
			/* Restore original Post Data */
			wp_reset_postdata();
		}
	}
	
	$landingvalues= get_post_meta( $tournamentsID,'landing');
	if(isset($landingvalues[0]) && is_numeric($landingvalues[0]) && $landingvalues[0] > 0) {
		$landingpost = new WP_Query(array( 'p' => $landingvalues[0],'post_type'=> 'landings' ));
		if ( $landingpost->have_posts() ) {
			while ( $landingpost->have_posts() ) {
				$landingpost->the_post();
				$lake .=  ' <span class="mini_splitter">|</span> <a href="'.get_permalink().'" ><span style="text-transform:uppercase;" class="post_info_date">'.get_the_title().'</span></a>';
			}
			/* Restore original Post Data */
			wp_reset_postdata();
		}
	}
	$featured = get_field( 'featured', $tournamentsID );
	$is_featured = (  ( isset( $featured[0] ) && $featured[0] == 'yes' ) ? 'is_featured' : '' );
?>
<a class="<?=$is_featured;?>" href="<?php echo get_the_permalink( $tournamentsID );?>" title="<?php echo titlechange( get_the_title( $tournamentsID ) );?>"><?php echo titlechange( get_the_title( $tournamentsID ) );?></a>
<!-- <div class="trail_info"><?php echo $trail; ?> <?php echo $lake; ?></div> -->
<hr />

<?php  }
	}
?>