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

  • @soph I am not a beginner at PHP and I find array_multisort() overly complex, so don’t feel this is the problem. I find that using usort() is much more straight forward. The idea is that you create your own sorting function and call it with the array of the repeater and then use any of the fields on the row to determine the order. This is a basic example I posted here, but I’ll repeat it

    // get the entire repeater in a multidimensional array
    $repeater = get_field('repeater');
    usort($repeater, 'sort_by_email');
    // usort function
    function sort_by_email($a, $b) {
      if ($a['email'] == $b['email']) {
        return 0;
      } elseif ($a['email'] < $b['email']) {
        return -1;
      } else {
        return 1;