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;
}
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.