Home Forums ACF PRO Sorting repeater fields by date Reply To: Sorting repeater fields by date

  • Thank you for your help, I tried to use your code and it doesn’t seem to work quite yet. Also I made some modifications :

    // get the entire repeater in a multidimensional array
    $repeater = get_field('agenda_test');
    // set starting month and count
    // we need a counter to know if we're on the first row
    $previous_month = '';
    $count = 0;				
    foreach ($repeater as $row) {
      echo "</br>";
      // make sure that your date field is returning a valid date format
      // or this will not work
      $this_month = date('F', strtotime($row['date']));
      if ($this_month != $previous_month) {
         // month has changed
         if ($count > 0) {
           // close the previously opened container
           // the container is opened below						
           </div><!-- .month -->
         } // end in count > 0 (i.e. not first row)
         // open a new container and display the month
         <div class="month">
         <div class="the_month"><?php echo $this_month; ?></div>
         // update previous month value for next loop
         $previous_month = $this_month;
       } // end if new month
       // output additional sub fields here
       // increment count
    } // end foreach row

    And this what I get in return:

    array(2) { [“date”]=> string(10) “02/02/2019” [“texte_test”]=> string(42) “Premier texte de ce qu’il se passe ce mois” }

    array(2) { [“date”]=> string(10) “15/02/2019” [“texte_test”]=> string(28) “Un autre texte pour février” }

    array(2) { [“date”]=> string(10) “05/04/2019” [“texte_test”]=> string(53) “Un texte pour le mois d’acril, mais écrit avant mars” }

    array(2) { [“date”]=> string(10) “10/04/2019” [“texte_test”]=> string(29) “Ce texte est pour le 10 avril” }

    array(2) { [“date”]=> string(10) “02/03/2019” [“texte_test”]=> string(27) “Le jour de mon anniversaire” }

    I guess I have to format the date in some way, though I don’t know how. Also, I want the months in french if possible….