Home › Forums › Add-ons › Repeater Field › Order by date, repeater field
Hi Elliot,
Is there a easy way to sort posts by datepicker field? I manage to order by date within one post. But if there are more rows it will only sort inside that array. I have multiple dates in a post created by repeater field. I need to order them all… See array bellow.
array(2) {
[0]=> array(3) {
["event_start"]=> string(8) "20140111" ["event_end"]=> string(16) "20140112" ["url"]=> string(62) "www.dx.no/ebillett/velg_antall.php"
}
[1]=> array(3) {
["event_start"]=> string(8) "20140102" ["event_end"]=> string(16) "20140103" ["url"]=> string(62) "www.dx.no/ebillett/velg_antall.php"
}
}
Hi @eiriksk
Thanks for posting your repeater field data.
I have written a tutorial on how to sort a repeater field here:
http://www.advancedcustomfields.com/resources/how-to/how-to-sorting-a-repeater-field/
I don’t quite understand what you mean by ordering based on multiple dates per row. Perhaps you can explain the logic you want to achieve?
Thanks
E
I use ACF to post consert events. In each post I add playing times using repeater field with date picker. So each event can have multiple dates.
I manage to order one post by playing dates. But my question is how to sort many posts with different playing times. Order them chronology.
Actually you reapeat the post content, but with different date.
Hi @eiriksk
This will not be possible with any WP_Query args, so you will need to do this custom ordering with custom PHP logic.
Firstly, load the posts via the get_posts function, and then loop over them.
For each post, load in the playing dates data and use this data to construct an array where one of the columns is the playing time.
Then you can use the code in the above tutorial to sort this custom array based on the playing time.
Good luck
Thanks
E
The topic ‘Order by date, repeater field’ 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.