Advanced Custom Fields sort by field group sub field

Run a WordPress Query based on Advanced Custom Fields group sub field.


If you have an ACF group labelled “Date and Time” with a name of “date_and_time”. Inside this group you have sub fields called “Date” (date), “Start Time” (start_time) and “End Time” (end_time).

You can pull a query based on the sub fields using the ‘meta_key’ option like this:

   $args = array(
        'post_type' => 'event',
        'posts_per_page' => -1,
        'meta_key' => 'date_and_time_date',
        'orderby' => 'meta_value',
        'order' => 'ASC'
    $the_query = new WP_Query( $args );

This assumes your Date field has a return format of “Ymd”.

Leave a Reply

Your e-mail address will not be published. Required fields are marked *