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

  • Hi,

    Thanks for your answer. Something i don’t understand or it was not good. BUT, with this code it works fine for me:

    <?php 
                            /*build and fill: cp-loop and repeater loop*/
                            if(have_posts()) : while(have_posts()) : the_post(); 
                                $my_workshop_name = get_the_title();
    
                                if( have_rows('datums') ):
                                    while ( have_rows('datums') ) : the_row();
    
                                    $my_workshop_date = get_sub_field('datum');
                                    $the_ID = get_the_ID();
    
                                    /*of course you can extend this with additional fields or infos for that workshop that you can use later*/
                                    $workshops[$my_workshop_date][$the_ID]['date'] = $my_workshop_date;
                                    $workshops[$my_workshop_date][$the_ID]['name'] = $my_workshop_name;
                                    endwhile;
                                endif;
    
                            endwhile;
                            endif;
    
                            /*output*/
    
                            //    [20151201]=> array(1) { [29]=> array(2) { ["date"]=> string(8) "20151201" ["name"]=> string(18) "TEST123 4-12-2015" } } 
                            //$datum = date("Ymd");
    
                            ksort($workshops);
    
                            foreach ($workshops as $key_day => $row_day){
                                if ($key_day > date("Ymd")) {
                                    foreach ($row_day as $key_workshop => $row_workshop){
                                        $workshop_name = $row_workshop['name'];
                                        $workshop_date = $row_workshop['date'];
                                        echo $workshop_date .' : '. $workshop_name .'<br />';
                                    }
                                }
                            }
                        ?>