Please see my other thread, https://support.advancedcustomfields.com/forums/topic/sort-repeater-in-back-end-where-data-is-entered/ , which is marked solved for background on this. I didn’t see a way to mark it “unsolved” so I am creating a new thread.
When I put define('WP_DEBUG', true);
in wp-config.php. And have this in my functions.php file:
function my_acf_load_value( $rows ) {
foreach ( $rows as $key => $row ) {
$column_id[ $key ] = $row[ 'field_593c04d244712' ];
}
array_multisort( $column_id, SORT_ASC, $rows );
return $rows;
}
I get the following errors on the front end:
Warning: Invalid argument supplied for foreach() in functions.php on line 110
Warning: array_multisort(): Argument #1 is expected to be an array or a sort flag in functions.php on line 113
Line 110:
foreach ( $rows as $key => $row ) {
Line 113:
array_multisort( $column_id, SORT_ASC, $rows );
Not sure how to keep this filter functional AND prevent these Warnings. What do I need to do to prevent them?
I think where you have field_593c04d244712 it should be the name of the field, not the key.
Getting the same errors — and using name of field, not the key, so that’s not the problem/solution. Function runs, and sorts as intended, but would be nice to not have those errors.
start by dumping the value $rows before the foreach to see what it holds.
if the output is as expected, then dump $key and $row within the foreach.
I think there is either an error in $rows or $key.
Thanks @beee — repeater was NULL on some pages, neglected to include the pre-repeater-loop sort in the if
statement.