Home Forums ACF PRO Sorting a nested repeater field by subfield


Sorting a nested repeater field by subfield

  • I have a repeater field nested 2 levels deep that I need to sort by a number subfield. I’ve tried following the examples provided here but haven’t had much luck.

    Here is my code as currently constructed, which displays everything correctly, I’d just like to have the ‘member_repeater’ sort by its ‘percentage_complete’ subfield.

        <div class="leaderboard">
            <?php if( have_rows('team_repeater') ): ?>
                <?php while( have_rows('team_repeater') ): the_row(); 
                    $teamName = get_sub_field('team_name');
                    $teamNameLowercase = strtolower($teamName);
                    $teamValue = str_replace(' ', '', $teamNameLowercase); ?>
                    <?php if (have_rows('leaderboard_repeater')): ?>
                        <?php while(have_rows('leaderboard_repeater')): the_row(); 
                            $type = get_sub_field('leaderboard_type'); 
                            $count = 0;
                            <div class="leaderboard-list <?php echo $type ?>-list" data-team="<?php echo $teamValue ?>">
                                <?php while( have_rows('member_repeater') ): the_row();
                                    $department = get_sub_field('department_name');
                                    $team_member_name = get_sub_field('member_name');
                                    $percentage = get_sub_field('percentage_complete');
                                    $count++; ?>
                                    <div class="leaderboard-item">
                                        <div class="leaderboard-item-count">
                                            <span><?php echo $count ?></span>
                                        <div class="leaderboard-item-info">
                                            <div class="item-info-left">
                                                <p class="member-department"><?php echo $department; ?></p>
                                                <p class="member-name"><?php echo $team_member_name; ?></p>
                                            <div class="item-info-right">
                                                    <?php if ($type == 'giving') { 
                                                        echo 'Donors';
                                                    } elseif ($type == 'volunteering') {
                                                        echo 'Volunteers';
                                                    } else {
                                                        echo 'Amount';
                                                    } ?>
                                                <p class="percent"><?php echo $percentage ?><span>%</span></p>
                                            <div class="progress">
                                                <div class="progress-bar" role="progressbar" style="width: <?php echo $percentage; ?>%" aria-valuenow="<?php echo $percentage ?>" aria-valuemin="0" aria-valuemax="100"></div>
                                <?php endwhile; ?>
                        <?php endwhile; ?>
                    <?php endif; ?>
                <?php endwhile; ?>
            <?php endif; ?>

    Any help would be appreciated. Thanks!

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.