Support

Account

Home Forums Add-ons Repeater Field Order repeater and update_sub_field

Solving

Order repeater and update_sub_field

  • Hello,

    I’m sorting my repeater with multisort. But I also have a update_sub_field() function in the repeater. On every page update the rows change place. It seems like update_sub_field() updates the wrong row?

    page.php

    if( have_rows('betters', 309) ):
       while( have_rows('betters', 309) ) : the_row();
          //...
          update_sub_field('field_5963e28c37f7b', "{$points}");
       endwhile;
    endif;

    functions.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['field_5963e28c37f7b'];
    	}
    
    	// multisort
    	array_multisort( $order, SORT_DESC, $value );
    
    	// return
    	return $value;
    }
    
    add_filter('acf/load_value/name=betters', 'my_acf_load_value', 10, 3);
  • Hi @felixzb2 I have this exact problem. Did you ever figure out a solution?

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Order repeater and update_sub_field’ is closed to new replies.