Home › Forums › ACF PRO › Sort a repeater field by date (and store it) › Reply To: Sort a repeater field by date (and store it)
This is my meta query.
$query->set( 'meta_query', array(
'tour_clause' => array(
'key' => 'sd_tour_schedule_%_until',
'value' => date( 'Ymd' ),
'compare' => '>'
),
'move_up_clause' => array(
'key' => 'sd_move_item_up_timestamp',
'compare' => 'EXISTS'
),
));
$query->set( 'orderby', array( 'tour_clause' => 'ASC', 'move_up_clause' => 'DESC' ) );
And the filter which is called.
function sd_tour_city_filter( $where ) {
global $wpdb;
$where = str_replace(
"meta_key = 'sd_tour_schedule_%",
"meta_key LIKE 'sd_tour_schedule_%",
$wpdb->remove_placeholder_escape( $where )
);
return $where;
}
It returns the output but sorts by the row numbers/index. Hence why the order needs to be correct in the back-end and that’s why the order has to be ‘re-stored’ after saving a post. I disabled the ordering of repeaters on the front-end so users can’t change this. I don’t want them to think about this.
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.