Hi, I would like to know how to sort a repeater field when some of the words can have accents (french names).
Here is my code
function my_acf_load_value( $value, $post_id, $field ) {
// vars
$order = array();
// bail early if no value
if( empty($value) ) {
return $value;
}
// populate order
foreach( $value as $i => $row ) {
$order[ $i ] = $row['field_5ab126349ce3a'];
}
// multisort
array_multisort( $order, SORT_DESC, $value );
// return
return $value;
}
add_filter('acf/load_value/key=field_5ab126349ce3a', 'my_acf_load_value', 10, 3);
Here is the result
Mathieu
Roland
Rébecca
Zac
Édouard
Roland should be after Rébecca and Édouard should be first
There isn’t any way to do this. I did a search on ‘php sort words with accented letters in correct order’ and found only the results that say it can’t be done short of building your own comparison functions. PHP sorts base on the numeric value of the character in the character set. https://stackoverflow.com/questions/39035477/php-natsort-with-accented-letters