Support

Account

Home Forums Backend Issues (wp-admin) Sorting Repeater Field, in ADMIN, by a date?

Unread

Sorting Repeater Field, in ADMIN, by a date?

  • Hey, I’m trying to modify the function circuuz posted here: https://support.advancedcustomfields.com/forums/topic/sort-on-repeater-field-in-admin/

    Do I understand correctly that this sorts the field in the ADMIN editing screen? And does it work for options panels?

    I have a few hundred items in a repeater, and one of the sub_fields is a date value. I’d love to be able to sort all those fields by the date. Is that possible?

    Here’s the function as circuuz posted it:

    function my_acf_update_value( $value, $post_id, $field  ) {
    	$mc_sort_id_FIELD_KEY = 'field_xxxxxxxx'; // Set this to the field key of your field called "mc_sort_id".
    	
    	$order = [];
    
    	foreach ( $repeater as $i => $row ) {
    		$order[ $i ] = $row[ $mc_sort_id_FIELD_KEY ];
    	}
    
    	array_multisort( $order, SORT_ASC, $value );
    	
    	return $value;
    }
    add_filter( 'acf/update_value/name=my_repeater_field', 'my_acf_update_value', 10, 3 );
Viewing 1 post (of 1 total)

The topic ‘Sorting Repeater Field, in ADMIN, by a date?’ is closed to new replies.