Home › Forums › Backend Issues (wp-admin) › Sort Repeater in BACK end, Where Data is Entered
I know we can drag and drop to reorder repeater records. I have a very long employee schedule with 50+ records to drag and drop and employees coming and going all the time. So I was hoping when a record is created, that when the page is updated it will reorder the list alphabetically so that the next time the list is edited, it is alphabetically listed. I know I can sort these on the front end, this is for the backend.
hi, i think something like that should work
add_filter('acf/load_value/name=repeater_termin', 'my_acf_load_value', 10, 3); //repeater_name
function my_acf_load_value( $rows)
{
foreach( $rows as $key => $row ) {
$thedate = $row['termin_date']; //datepicker_fieldname
$column_id[ $key ] = strtotime($thedate);
}
array_multisort( $column_id, SORT_ASC, $rows );
return $rows;
}
Put that in the functions.php file? I want it alphabetized by Name. Is that sorting by the time it was entered?
Field Group: Schedules
Repeater: Employee Schedule (employee_schedule)
Sub-Field to Sort By: Name (name)
Should I change ‘repeater_termin’ to ’employee_schedule’?
Should I change ‘termin-date’ to ‘name’?
Here is my current code in functions.php:
add_filter('acf/load_value/name=employee_schedule', 'my_acf_load_value', 10, 3); //repeater_name
function my_acf_load_value( $rows)
{
foreach( $rows as $key => $row ) {
$thename = $row['name']; //Field You Want To Sort By
$column_id[ $key ] = strtotime($thename);
}
array_multisort( $column_id, SORT_ASC, $rows );
return $rows;
}
I’ve tried many things now. Nothing is sorting the repeater in the backend. Any help would be greatly appreciated. My repeater:
Field Group: Schedules
Repeater Label: Employee Schedule
Repeater Field Name: employee_schedule
(Sub-Field to Sort By) Field Label: Name
(Sub-Field to Sort By) Field Name: name
Sub-Field Checkbox(same for each day of week with just different day) Field Label: Mon
Sub-Field Checkbox(same for each day of week with just different day) Field Name: monday
Sub-Field Checkbox Mon Choices:
Day : Mon DAY
Night : Mon NIGHT
I figured it out. I was trying to draw the front-end field name. I needed to go into SQL and get the correct row used there.
add_filter('acf/load_value/name=employee_schedule', 'my_acf_load_value', 10, 3); //repeater_name
function my_acf_load_value( $rows)
{
foreach( $rows as $key => $row ) {
$column_id[ $key ] = $row['field_5625599634aa1'];
}
array_multisort( $column_id, SORT_ASC, $rows );
return $rows;
}
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?
The topic ‘Sort Repeater in BACK end, Where Data is Entered’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.