Support

Account

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 ?