php – Group Upcoming Events and Custom Past Events of Key ACFs

I have a problem that groups the next events and past events with their own specific headers. A visual example of this would be:

— Upcoming events —-

  • event – – event – – event – – event – etc …

— Past events —-

  • event – – event – – event – – event – etc …

These should also be ordered with the most recent events first.

Here is my code at the time it returns the events based on the selected filters:

$ genres = $ _POST['genres'];
$ types = $ _POST['types'];
$ dateFrom = $ _POST['dateFrom'];
$ dateTo = $ _POST['dateTo'];

if ($ dateFrom == & # 39; anytime & # 39;) {
$ dateFrom = & # 39; 1900-01-01 & # 39 ;;
}

if ($ dateTo == & # 39; anytime & # 39;) {
$ dateTo = & # 39; 3000-01-01 & # 39 ;;
}

// ELIMINATE ALL GENRES / ALL TYPES WHEN ANOTHER FILTER IS SELECTED
yes ($ genres[0] ! == & # 39; genres & # 39; && $ types[0] == & # 39; all types & # 39;) {
$ typesQuery = false;
} else {
$ typesQuery = array (
& # 39; taxonomy & # 39; => & # 39; types & # 39 ;,
& # 39; field & # 39; => & # 39; slug & # 39 ;,
& # 39; terms & # 39; => $ types
);
}
yes ($ types[0] ! == & # 39; all types & # 39; && $ genres[0] == & # 39; all genres & # 39;) {
$ genresQuery = false;
} else {
$ genresQuery = array (
& # 39; taxonomy & # 39; => & # 39; genres & # 39 ;,
& # 39; field & # 39; => & # 39; slug & # 39 ;,
& # 39; terms & # 39; => $ genres
);
}


// Build the query to do the filtering!
$ args = array (
& # 39; posts_per_page & # 39; => -1,
& # 39; numberposts & # 39; => 1000,
& # 39; post_type & # 39; => & # 39; whats_on & # 39 ;,
& # 39; tax_query & # 39; => array (
& # 39; relationship & # 39; => & # 39; O & # 39 ;,
$ genresQuery,
$ typesQuery
)
& # 39; meta_query & # 39; => array (
training(
& # 39; relationship & # 39; => & # 39; O & # 39 ;,
& # 39; range_date_from & # 39; => array (
& # 39; key & # 39; => & # Sections_1_event_dates_range_0_date_from & # 39 ;,
& # 39; value & # 39; => array ($ dateFrom, $ dateTo),
& # 39; Compare & # 39; => & # 39; ENTER & # 39 ;,
& # 39; type & # 39; => & # 39; DATE & # 39 ;,
)
& # 39; range_date_to & # 39; => array (
& # 39; key & # 39; => & # Sections_1_event_dates_range_0_date_to & # 39 ;,
& # 39; value & # 39; => array ($ dateFrom, $ dateTo),
& # 39; Compare & # 39; => & # 39; ENTER & # 39 ;,
& # 39; type & # 39; => & # 39; DATE & # 39 ;,
)
& # 39; individual_date_from & # 39; => array (
& # 39; key & # 39; => & # 39; sections_1_event_dates_0_date & # 39 ;,
& # 39; value & # 39; => array ($ dateFrom, $ dateTo),
& # 39; Compare & # 39; => & # 39; ENTER & # 39 ;,
& # 39; type & # 39; => & # 39; DATE & # 39 ;,
)
& # 39; individual_date_to & # 39; => array (
& # 39; key & # 39; => & # 39; sections_1_event_dates_1_date & # 39 ;,
& # 39; value & # 39; => array ($ dateFrom, $ dateTo),
& # 39; Compare & # 39; => & # 39; ENTER & # 39 ;,
& # 39; type & # 39; => & # 39; DATE & # 39 ;,
)
)
)
& # 39; orderby & # 39; => array (
& # 39; range_date_from & # 39; => & # 39; DESC & # 39 ;,
& # 39; individual_date_from & # 39; => & # 39; DESC & # 39;
)
);
$ filterEvents = new WP_Query ($ args);

// echo $ filterEvents-> request;
// die;

$ html = "http://wordpress.stackexchange.com/";
if ($ filterEvents-> have_posts ()):

$ html = & # 39;

UPCOMING EVENTS

& # 39 ;; while ($ filterEvents-> have_posts ()): $ filterEvents-> the_post (); $ eventId = get_the_ID (); $ tags = wp_get_post_terms ($ eventId, array (& # 39; genres & # 39 ;, & # 39; types & # 39;), array ("fields" => "all")); $ eventIndividualData = get_field (& # 39; sections & # 39 ;, $ eventId)[1]['event_dates']; $ eventRangeData = get_field (& # 39; sections & # 39 ;, $ eventId)[1]['event_dates_range']; // var_dump ($ eventIndividualData); // var_dump ($ eventRangeData); $ html = & # 39;& # 39 ;; in the end it will end yes;

Any help would be seriously appreciated.

Thank you.