Home › Forums › Add-ons › Repeater Field › Sort by date a repeater field › Reply To: Sort by date a repeater field
Hi @James
Thank you for your help, I’ve explored all your link.
To answer your question : I am trying to sort a repeater from a single page, so the current post I guess ?
I am trying to this (in the “Advanced” part).
A code that allow to sort front and backend.
https://www.advancedcustomfields.com/resources/how-to-sorting-a-repeater-field/.
So I use this code in my function.php
<? 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['date'];
}
// DATE is my time sub field.
// multisort
array_multisort( $order, SORT_DESC, $value );
// return
return $value;
}?>
<? add_filter('acf/load_value/name=scores', 'my_acf_load_value', 10, 3);?>
And I have the same code (the one that is in my question) on my template.php
Could you give me a hand ?
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.