Hello guys ! I’ve got a problem and i can’t find the answer anywhere.
I’ve got a post_type called : show
In this post type there is a repeater_field called : event
And in this repeater_field there is a sub_field : start_date and start_time
I would like to query all posts and get a result like this :
17/04/2018 – 10:00 – Show 3
18/04/2018 – 10:00 – Show 1
18/04/2018 – 11:00 – Show 2
18/04/2018 – 12:00 – Show 1
Anyone can help me ?
I had a similar issue recently also working on show listings.
You can do a regular query retrieving the posts then do a get_fields for all fields of that post, then sort the array. Check out Answer 1 below for that one.
https://stackoverflow.com/questions/2699086/sort-multi-dimensional-array-by-value
I chose to create a custom query joining to the postmeta table twice. Once for the date and once for the time. Like
SELECT * WPPREFIX_posts p
INNER JOIN WPPREFIX_postmeta m1 ON p.ID = m1.post_id
INNER JOIN WPPREFIX_postmeta m2 ON p.ID = m2.post_id
WHERE m1.meta_key = 'start_date' AND m2.meta_key = 'start_time'
ORDER BY m1.meta_value,m2.meta_value
This allows you to sort by each meta value.
Hope this helps