Support

Account

Home Forums Add-ons Repeater Field Sort by key in repeater field Reply To: Sort by key in repeater field

  • That might be the way I’d go if I had to do it as well. Quite honestly the whole array_multisort thing hurts my head.

    For the future for anyone that finds this, I did find an alternate solution, you could also try using usort() http://php.net/manual/en/function.usort.php.

    
    // 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;
      }
    }