Last active
October 7, 2021 14:02
-
-
Save itsHall/8fbb5e23f69c4cf9468a884f4bcbdc01 to your computer and use it in GitHub Desktop.
Sort Repeater By Sub Field Alphabetically | Timber/Twig/WordPress
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Get repeater value | |
$repeater = get_field('team', [--POST ID--]); | |
// Obtain sub fields | |
foreach ($repeater as $key => $row) { | |
$the_image[$key] = $row['image']; | |
$the_first_name[$key] = $row['first_name']; | |
$the_last_name[$key] = $row['last_name']; | |
} | |
// Sort the repeater by last name sub field, ascending | |
array_multisort($the_last_name, SORT_ASC, $repeater); | |
// Add repeater to context | |
$context['repeater'] = $repeater; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment