From Wet Lizard, 10 Years ago, written in Plain Text.
This paste is a reply to sort custom posts by custom meta value data from Dan - view diff
Embed
  1. while ($sunday_query->have_posts()) {
  2.     $sunday_query->the_post();
  3.     $sort_array = [];
  4.     $schedules = get_post_meta($post->ID, 'show_sched', false);
  5.     $title = get_the_title();
  6.    
  7.     usort($schedules, function ($a, $b) {
  8.         return $a[0]['start_hour'] > $b[0]['start_hour'] ? 1 : -1;
  9.     });
  10.  
  11.     array_filter($schedules, function ($schedule) {
  12.         return $schedule['day'] === 'Sunday';
  13.     }
  14.  
  15.     foreach($sort_array as $sort) {
  16.         foreach($sort as $key => $value) {
  17.             $day = $value['day'];
  18.             $order = $value['start_hour'];
  19.            
  20.             echo $day.', ' . $order . ', ' . $title . '<br>';
  21.         }
  22.     }
  23. }