From dan, 10 Years ago, written in Plain Text.
Embed
  1. $days = array();
  2. $days['sunday'] = array();
  3. $days['monday'] = array();
  4. $days['tuesday'] = array();
  5. $days['wednesday'] = array();
  6. $days['thursday'] = array();
  7. $days['friday'] = array();
  8. $days['saturday'] = array();
  9.  
  10. // initialization for $inner_args & backup the current global $post
  11. $sunday_args = array(
  12.         'post_type' => 'show',
  13.         'posts_per_page' => '-1'
  14.     );
  15. $sunday_query = new WP_Query($sunday_args);
  16.  
  17. echo '<ul class="show_list">';
  18.  
  19. while ($sunday_query->have_posts()) : $sunday_query->the_post();
  20.  
  21.     $temp_array = array();
  22.     $schedules = get_post_meta($post->ID, 'show_sched', false);
  23.     $title = get_the_title();
  24.  
  25.     if($title == 'Dan Test') {
  26.         //echo '<pre>';
  27.         //var_dump($schedules); exit;
  28.     }
  29.  
  30.     foreach($schedules as $s):
  31.  
  32.         foreach($s as $schedule):
  33.  
  34.             $temp_array = array();
  35.  
  36.             $theday = $schedule['day'];
  37.             $theorder = $schedule['start_hour'];
  38.             $themeridian = $schedule['start_meridian'];
  39.  
  40.             if(!empty($themeridian) && strtolower($themeridian == 'pm')) {
  41.                 $theorder += 12; // $theorder equals $theorder + 12
  42.             }
  43.  
  44.             $temp_array['title'] = $title;
  45.             $temp_array['link'] = get_the_permalink();         
  46.             $temp_array['day'] = $theday;
  47.             $temp_array['order'] = $theorder;
  48.  
  49.             $days[strtolower($theday)][$theorder] = $temp_array;
  50.  
  51.         endforeach;
  52.  
  53.     endforeach;
  54.  
  55. endwhile;
  56.  
  57. foreach($days as $day) {
  58.  
  59.     ksort($day);
  60.  
  61.     foreach($day as $d) {
  62.  
  63.         $theday = $d['day'];
  64.         $theorder = $d['order'];
  65.         $title = $d['title'];
  66.  
  67.         if($theday == 'Sunday') {
  68.  
  69.             echo '<li class="show">';
  70.                 echo '<span>'.$theorder.'</span>';
  71.                 echo '<div>'.$title.'</div>';
  72.             echo '</li>';
  73.  
  74.         } elseif($theday == 'Monday') {
  75.  
  76.             echo '<li class="show">';
  77.                 echo '<span>'.$theorder.'</span>';
  78.                 echo '<div>'.$title.'</div>';
  79.             echo '</li>';
  80.  
  81.         } elseif($theday == 'Tuesday') {
  82.  
  83.             echo '<li class="show">';
  84.                 echo '<span>'.$theorder.'</span>';
  85.                 echo '<div>'.$title.'</div>';
  86.             echo '</li>';
  87.  
  88.         } elseif($theday == 'Wednesday') {
  89.  
  90.             echo '<li class="show">';
  91.                 echo '<span>'.$theorder.'</span>';
  92.                 echo '<div>'.$title.'</div>';
  93.             echo '</li>';
  94.  
  95.         } elseif($theday == 'Thursday') {
  96.  
  97.             echo '<li class="show">';
  98.                 echo '<span>'.$theorder.'</span>';
  99.                 echo '<div>'.$title.'</div>';
  100.             echo '</li>';
  101.  
  102.         } elseif($theday == 'Friday') {
  103.  
  104.             echo '<li class="show">';
  105.                 echo '<span>'.$theorder.'</span>';
  106.                 echo '<div>'.$title.'</div>';
  107.             echo '</li>';
  108.  
  109.         } elseif($theday == 'Saturday') {
  110.  
  111.             echo '<li class="show">';
  112.                 echo '<span>'.$theorder.'</span>';
  113.                 echo '<div>'.$title.'</div>';
  114.             echo '</li>';
  115.  
  116.         } else {}
  117.     }
  118. }
  119.  
  120. echo '</ul>';