I tried some of the methods from this post: Sort array by object property in PHP?
But I am not able to sort by the last name of my person array in wordpress.
Here is what I do:
<?php
function personSort( $a, $b ) {
return $a->last_name == $b->last_name ? 0 : ( $a->last_name > $b->last_name ) ? 1 : -1;
}
usort( $autlist, 'personSort' );
foreach($autlist as $al){ ?>
<option value="<?php echo $al->ID; ?>"><?php echo $al->first_name.' '.$al->last_name; ?></option>
The order comes out like this:
Nick Hammond
Peter Ruck
Nam Ol Lamon
What am I doing wrong?