Skip to content

Instantly share code, notes, and snippets.

@itsHall
Last active October 7, 2021 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itsHall/8fbb5e23f69c4cf9468a884f4bcbdc01 to your computer and use it in GitHub Desktop.
Save itsHall/8fbb5e23f69c4cf9468a884f4bcbdc01 to your computer and use it in GitHub Desktop.
Sort Repeater By Sub Field Alphabetically | Timber/Twig/WordPress
<?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