Site icon Hip-Hop Website Design and Development

Query posts and display all dates in repeater field in chronological order

I have a Custom Post Type ‘Production’ with ‘Tourdates’ as a repeaterfield (using Advanced Custom Field plugin).
Tourdates have a ‘Date & Time Picker ‘field named ‘Playdate’.

I would now like to display (in a list) all Playdates of all Productions sorted chronologically.

My current query displays the posts like this:

But I’m looking to get them displayed like this:

My code:

    $args = array(
    'numberposts'           => -1,
    'post_status'           => 'publish',
    'post_type'                 => 'productie',
    'suppress_filters'  => false,
);

$the_query = new WP_Query( $args );

if ( $the_query->have_posts() ) : 
    while ( $the_query->have_posts() ) : 
        $the_query->the_post();

    $productienaam = get_the_title();

        if( have_rows('tourdata') ):
        while ( have_rows('tourdata') ) : the_row();

                $speeldatum = get_sub_field('speeldatum');
                $the_ID = get_the_ID();

                $productie[$speeldatum][$the_ID]['speeldatum'] = $speeldatum;
                $productie[$speeldatum][$the_ID]['name'] = $productienaam;
            endwhile;
      endif;

    endwhile;
endif;

// $speeldatum = date("Ymd");

asort($productie);

foreach ($productie as $key_day => $row_day){
  if ($key_day > date("Ymd")) {
    foreach ($row_day as $key_productie => $row_productie){
        $productie_name = $row_productie['name'];
      $productie_date = $row_productie['speeldatum'];
      echo $productie_date .' : '. $productie_name .'<br />';
    }
  }}