Thanks for the pointer to custom looper provider @ruenel. I have found a solution to what I wanted.
//============================================================
// CUSTOM LOOPER PROVIDER FUNCTION TO GET UNIQUE EVENTS / DATES
//============================================================
function custom_mec_events_query() {
$current_date = date('Y-m-d');
$event_category_ids = [53, 54, 55];
$location_ids = [56, 57, 43];
$args = array(
'post_type' => 'mec-events',
'post_status' => 'publish',
'meta_key' => 'mec_start_date',
'meta_query' => array(
array(
'key' => 'mec_start_date',
'value' => $current_date,
'compare' => '>=',
'type' => 'DATE',
),
),
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'mec_category',
'field' => 'term_id',
'terms' => $event_category_ids,
'operator' => 'IN',
),
array(
'taxonomy' => 'mec_location',
'field' => 'term_id',
'terms' => $location_ids,
'operator' => 'IN',
),
),
'orderby' => array(
'meta_value' => 'ASC', // Meta key sorting should reference 'meta_value'
'title' => 'ASC', // Sort by title as fallback
),
'posts_per_page' => 1000, // Increase number of results
);
$query = new WP_Query($args);
if ($query->have_posts()) {
$unique_events = [];
$seen_pairs = [];
foreach ($query->posts as $post) {
$event_start_date = get_post_meta($post->ID, 'mec_start_date', true);
$location_terms = get_the_terms($post->ID, 'mec_location');
$location_name = $location_terms && !is_wp_error($location_terms) ? join(', ', wp_list_pluck($location_terms, 'name')) : '';
$pair = $event_start_date . '|' . $location_name;
if (!in_array($pair, $seen_pairs)) {
$seen_pairs[] = $pair;
$unique_events[] = array(
'event_id' => $post->ID,
'event_title' => $post->post_title,
'event_start_date' => $event_start_date,
'location_name' => strip_tags($location_name),
);
}
}
wp_reset_postdata(); // Reset post data here
return $unique_events;
} else {
// Handle no events found scenario (optional)
return array();
}
}
// Register the custom Looper Provider
add_filter('cs_looper_custom_custom_mec_events', function($result) {
return custom_mec_events_query();
});
Looper Provider type: Custom
Hook: custom_mec_events
Looper Consumer Fields (note this is using Dynamic Content 2.0 in Pro 6.5.0 Beta 4)
{{ looper.field({"key":"event_start_date"})|date('l, jS F Y') }}
{{ looper.field({"key":"location_name"}) }}
This all provides unique date / location events where there may be multiple events on a day in a location.