DidouS

Reorder repeater values

Feb 26th, 2021 (edited)
206
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. add_filter('acf/load_value/name=basic_repeater', 'kunst_reorder_repeater', 10, 3);
  2. /**
  3.  *
  4.  */
  5. function kunst_reorder_repeater( $value, $post_id, $field ) {
  6.    
  7.     // vars
  8.     $order = array();
  9.  
  10.     // bail early if no value
  11.     if( empty($value) ) {
  12.         return $value;
  13.     }
  14.    
  15.     // populate order
  16.     foreach( $value as $i => $row ) {
  17.         $order[ $i ] = $row['field_6027a4c8e149b'];
  18.     }
  19.    
  20.     // multisort
  21.     array_multisort( $order, SORT_DESC, $value );
  22.    
  23.     // return  
  24.     return $value;
  25.    
  26. }
RAW Paste Data