Home › Forums › Front-end Issues › sorting entries in repeater post object field › Reply To: sorting entries in repeater post object field
Hi @rudtek
You need to get the post title for the order sort. It should be something like this:
function my_acf_sort_post_object( $value, $post_id, $field ) {
// vars
$order = array();
// bail early if no value
if( empty($value) ) {
return $value;
}
// populate order
foreach( $value as $i => $post_id ) {
$post_title = get_the_title($post_id);
$order[ $i ] = $post_title;
}
$order_lowercase = array_map('strtolower', $order);
// multisort
array_multisort( $order_lowercase, SORT_ASC, SORT_STRING, $value );
// return
return $value;
}
add_filter('acf/load_value/name=session_speaker', 'my_acf_sort_post_object', 10, 3);
Could you please test it out?
I hope this helps 🙂
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.