Home Forums Add-ons Repeater Field ACF query posts by date sub field Reply To: ACF query posts by date sub field

  • 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.

    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