Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $today = date("Y-m-d 00:00"); //set today's date
- $todaytext = date("l"); // define $todaytext with written out days
- for ($i=0; $i<7; $i++){
- $thedate = strtotime ( '+'.$i.' day' , strtotime ( $today ) ) ;
- $thedate = date ( 'Y-m-d H:i' , $thedate );
- $thedatetext = strtotime ( '+'.$i.' day' , strtotime ( $todaytext ) ) ;
- $thedatetext = date ( 'l' , $thedatetext );
- $future = strtotime ( '+24 hours' , strtotime ( $thedate ) ) ;
- $future = date ( 'Y-m-d H:i' , $future );
- $args = array(
- 'post_type' => 'event',
- 'orderby' => 'meta_value',
- 'order' => 'asc',
- 'meta_query' => array(
- 'relation' => 'OR',
- array(
- 'key' => 'opening_time',
- 'value' => array($today,$future),
- 'compare' => 'BETWEEN',
- 'type' => 'DATE'
- ),
- array(
- 'key' => 'artist_talk_time',
- 'value' => array($today,$future),
- 'compare' => 'BETWEEN',
- 'type' => 'DATE'
- )
- )
- );
- $event_query = new WP_Query( $args );
- if ($event_query->have_posts()) : while ($event_query->have_posts()) : $event_query->the_post();
- $keys = array('opening_time', 'film_time', 'artist_talk_time');
- $times = array(); // I tried putting the new array line here but then I got a repeat of the post for everyday
- $custom_field_keys = get_post_custom_keys();
- foreach ($custom_field_keys as $custom_field_key) {
- if (in_array($custom_field_key, $keys))
- {
- $custom_field_value = get_post_meta($post->ID, $custom_field_key, true);
- if ($custom_field_value >= $thedate && $custom_field_value <= $future) {
- $counttest++;
- $times[] = array($custom_field_value, $post->ID, $custom_field_key); // I changed the array here
- }
- }
- }
- endwhile;
- if ($counttest >0) {
- echo $counttest;
- if ($counttest>=2){
- echo ' Events ';
- } // end if ($totalevents>=2) function
- if ($counttest<2){
- echo ' Event ';
- }
- if ($thedate==$today){echo 'Today';}
- if ($thedate>$today){
- echo $thedatetext;}
- echo '<br>';
- }
- endif;
- $counttest=0;
- sort($times); // I changed the asort to sort here
- foreach ($times as $event) { $time_value = $event[0]; $post_id = $event[1]; $time_key = $event[2]; // changed the foreach here
- if ($time_key == 'opening_time') { ?>
- <li class="sidebar_event">
- <a href="<?php echo get_permalink($post_id) ?>" title="<?php echo get_the_title($post_id); ?>"> <?php echo get_the_post_thumbnail($post_id, 'upcoming_event_sidebar'); ?></a>
- <h2><a href="<?php echo get_permalink($post_id) ?>" title="<?php echo get_the_title($post_id); ?>"> <?php echo get_the_title($post_id); ?></a></h2>
- <h3>Opening</h3>
- <h4><?php echo get_post_meta($post_id,'event_venue', true);?> </h4>
- <h5><?php echo get_post_meta($post_id,'opening_time', true);?> </h5>
- </li><!-- end .sidebar_event -->
- <?php }
- else if ($time_key == 'artist_talk_time') { ?>
- <li class="sidebar_event">
- <a href="<?php echo get_permalink($post_id) ?>" title="<?php echo get_the_title($post_id); ?>"> <?php echo get_the_post_thumbnail($post_id, 'upcoming_event_sidebar'); ?></a>
- <h2><a href="<?php echo get_permalink($post_id) ?>" title="<?php echo get_the_title($post_id); ?>"> <?php echo get_the_title($post_id); ?></a></h2>
- <h3>Artist Talk</h3>
- <h4><?php echo get_post_meta($post_id,'event_venue', true);?> </h4>
- <h5><?php echo get_post_meta($post_id,'artist_talk_time', true);?> </h5>
- </li><!-- end .sidebar_event -->
- <?php }
- else if ($time_key == 'film_time') { ?>
- <li class="sidebar_event">
- <a href="<?php echo get_permalink($post_id) ?>" title="<?php echo get_the_title($post_id); ?>"> <?php echo get_the_post_thumbnail($post_id, 'upcoming_event_sidebar'); ?></a>
- <h2><a href="<?php echo get_permalink($post_id) ?>" title="<?php echo get_the_title($post_id); ?>"> <?php echo get_the_title($post_id); ?></a></h2>
- <h3>Artist Talk</h3>
- <h4><?php echo get_post_meta($post_id,'event_venue', true);?> </h4>
- <h5><?php echo get_post_meta($post_id,'artist_talk_time', true);?> </h5>
- </li><!-- end .sidebar_event -->
- <?php }
- }
- rewind_posts();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement