Home › Forums › ACF PRO › Sort a repeater field by date (and store it) › Reply To: Sort a repeater field by date (and store it)
After some testing, I think this will do the trick.
if ( isset( $_POST[ 'acf' ][ 'field_5a0de683a21cf' ] ) ) {
$tour_dates = get_field( 'sd_tour_schedule', $post_id );
if ( $tour_dates ) {
foreach ( $tour_dates as $key => $row ) {
$column_id[ $key ] = $row[ 'from' ];
}
array_multisort( $column_id, SORT_NUMERIC, $tour_dates );
$key = 0;
foreach ( $tour_dates as $key => $tour_info ) {
if ( is_array( $tour_info ) && count( $tour_info ) > 0 ) {
foreach( $tour_info as $column => $value ) {
if ( 'city' != $column ) {
$value = date( 'Ymd', (int) $value );
}
update_post_meta( $post_id, 'sd_tour_schedule_' . $key . '_' . $column, $value );
}
}
$key++;
}
}
}
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!
🚀 ACF & ACF PRO 6.0.7 are now available.
— Advanced Custom Fields (@wp_acf) January 18, 2023
✨This release contains bug fixes and improvements while we continue to work on the next major release of ACF.https://t.co/wQgAOpwmUI
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.