From 0afd5fda352f80267bbf210ab4f1f3ef4540c68d Mon Sep 17 00:00:00 2001 From: Antoine M Date: Wed, 4 Mar 2026 11:23:23 +0100 Subject: [PATCH] FEATURE Developing the new get_carhop_members_by_comity function to optmize reusabilty and data foramting for members of the team --- includes/utilities.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/includes/utilities.php b/includes/utilities.php index f4ef9be..c0661aa 100644 --- a/includes/utilities.php +++ b/includes/utilities.php @@ -323,3 +323,41 @@ function get_post_specific_type_terms($post_id) return $terms; } + + +function get_carhop_members_by_comity() +{ + + switch_to_blog(1); + + $comities_field_object = get_field_object('field_699737b48c0d2'); + $comities = $comities_field_object ? $comities_field_object['choices'] : []; + + $members_organised_by_comity = []; + + foreach ($comities as $comity_value => $comity_label) { + $members_posts_for_comity[$comity_value] = new WP_Query(array( + 'post_type' => 'equipe', + 'posts_per_page' => -1, + 'meta_key' => 'last_name', + 'orderby' => 'meta_value', + 'order' => 'ASC', + 'meta_query' => array( + array( + 'key' => 'comity', + 'value' => $comity_value, + 'compare' => 'LIKE', + ), + ), + )); + $members_organised_by_comity[$comity_value] = array( + 'name' => $comity_value, + 'label' => $comity_label, + 'members' => array_values($members_posts_for_comity[$comity_value]->posts), + 'count' => count($members_posts_for_comity[$comity_value]->posts), + ); + } + + restore_current_blog(); + return $members_organised_by_comity; +}