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

Question

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:

  • 09/04/2017 (Production x)
  • 28/12/2017 (Production y)
  • 07/04/2017 (Production x)
  • 11/04/2017 (Production x)
  • 31/04/2017 (Production y)
  • 14/04/2017 (Production y)

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

  • 07/04/2017 (Production x)
  • 09/04/2017 (Production x)
  • 11/04/2017 (Production x)
  • 14/04/2017 (Production y)
  • 31/04/2017 (Production y)
  • 28/12/2017 (Production y)

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 />';
    }
  }}
0
, , zuperuser 3 years 2020-04-07T08:51:58-05:00 0 Answers 85 views 0

Leave an answer

Browse
Browse