Home › Forums › Add-ons › Repeater Field › Repeater sub field display by group based on value › Reply To: Repeater sub field display by group based on value
including @friendofdog’s help
function shortByGroup($a, $b) {
if ($a['company_group'] > $b['company_group']) {
return 1;
} elseif ($a['company_group'] < $b['company_group']) {
return -1;
}
return 0;
}
$personArray = get_field('company_information');
if (!empty($personArray)) {
usort($personArray, 'sortByGroup');
$last_group = ''; // initialize the group name
$count = 0;
foreach ($personArray as $person) {
$this_group = $person['company_group'];
if ($this_group != $last_group) {
if ($count > 0) {
echo '</ul>';
}
echo '<h2>',$person['company_group'],'</h2><ul>';
}
$company = $person['company_name'];
if ($person['company_website']) {
$company = '<a href="'.$person['company_website'].'">'.
$company_name.'</a>';
}
echo '<li>',$company,'</li>';
} // end foreach
} // end if personArray
echo '</ul>';
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.