Support

Account

Home Forums Add-ons Repeater Field Sort posts by date picker in repeater field Reply To: Sort posts by date picker in repeater field

  • i think you need to loop through your CP and Repeater and build a array first, and after that echo workshops out of that array.
    important for ordering by date is: that you set Return Format to Ymd (you can change this later with date/date_i18n)

    /*build and fill: cp-loop and repeater loop*/
    if(have_posts()) : while(have_posts()) : the_post(); 
    $my_workshop_name = get_field('my_workshop_name');
    if( have_rows('dates') ):
        while ( have_rows('dates') ) : the_row();
    
    $my_workshop_date = get_sub_field('date');
    $the_ID = get_the_ID();
    
    /*of course you can extend this with additional fields or infos for that workshop that you can use later*/
    $array[$my_workshop_date][$the_ID]['date'] = $my_workshop_date;
    $array[$my_workshop_date][$the_ID]['name'] = $my_workshop_name;
    endwhile;
    endif;
    
    endwhile;
    endif;
    
    /*output*/
    
    asort($array);
    
    foreach ($my_workshop_date as $key_day => $row_day){
    foreach ($row_day as $key_workshop => $row_id){
    $workshop_name = $row_id['name'];
    $workshop_date = $row_id['date'];
    $workshop_date_pretty = date_i18n( 'j. F Y', $workshop_date);
    echo $workshop_date_pretty .' : '. $workshop_name;
    }
    }
    

    hope that help