Support

Account

Home Forums Backend Issues (wp-admin) Sort on repeater field in admin Reply To: Sort on repeater field in admin

  • To follow up on the idea John Huebner mentioned to use the acf/update_value filter.

    First you will need the field key of the field you have named “mc_sort_id”.
    To get that go to the Field Group admin page, click the “display field key” button in help dropdown, then copy the “mc_sort_id”-field key (looking something like this “field_1231313”).
    Then you should be able to use the following code in your functions.php file.
    Just remember to replace “my_repeater_field” with the name of your repeater field and also replace “field_xxxxxxxx” with the field key you copied above.

    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 );