Support

Account

Home Forums ACF PRO Repeater reverse order in admin area

Solved

Repeater reverse order in admin area

  • Hi,
    First off: GREAT JOB on the ACF. I use it on almost all my sites ๐Ÿ™‚
    Thanks for being awesome !

    Anyway…

    I have a site for a client that is Admin based only… No front end.

    I created a CPT with ACF repeater fields in January this year.

    Now the client called me up to ask me if I can reverse the order in admin area.

    So I started my google search and found alot of articles on how to do this on the front end, but no instructions on how to do this on the backend(Admin area).
    I know I can drag and drop, but there are hundreds of repeats , so…

    Is this possible and how can I do it ?

    p.s. : One of the fields inside the repeater is a “Text field” that has a Date in the text-form of (DD-MM-YYYY HH:MM:SS) if that helps at all….. It is automatically generated upon creating a new repeat… Just thought i’d include that ๐Ÿ™‚

  • I dont want to sound pushy, but the owner just called and told me that its important I do this by tomorrow.

    Anyone that can help out ?

  • So,,, this was quite easy once I turned on my brain.
    The instructions were on the website all a long :-))

    function my_acf_load_value( $value, $post_id, $field ) {
    
        $order = array();
    
        if( empty($value) ) {
            return $value;
        }
    
        // populate order
        // Remember to change the field_5a4d0e70a5d3f to the field that you want to sort by
        foreach( $value as $i => $row ) {
            $order[ $i ] = $row['field_5a4d0e70a5d3f'];
        }
    
        array_multisort( $order, SORT_DESC, $value );
    
        return $value;
    }
    // Remember to change "book_repeater" to your repeater field name
    add_filter('acf/load_value/name=book_repeater', 'my_acf_load_value', 10, 3);
Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.