From f45c1d0b4032b4a0ed77aa8818937c3a37abde11 Mon Sep 17 00:00:00 2001 From: Antoine Date: Mon, 16 Mar 2026 10:17:47 +0100 Subject: [PATCH] FEATURE add get_authors_linked_to_posts function to retrieve authors associated with given posts via ACF field for enhanced content management --- includes/utilities.php | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/includes/utilities.php b/includes/utilities.php index c0661aa..ec574e7 100644 --- a/includes/utilities.php +++ b/includes/utilities.php @@ -361,3 +361,42 @@ function get_carhop_members_by_comity() restore_current_blog(); return $members_organised_by_comity; } + + + +/** + * Retourne les auteurs (posts du CPT "auteurs") réellement liés + * aux posts donnés via le champ ACF "authors". + * + * @param array $post_ids Liste d'IDs de posts + * @param string $acf_field_name Nom du champ ACF (par défaut "authors") + * @return array|WP_Post[] Liste de posts "auteurs" + */ +function get_authors_linked_to_posts(array $post_ids) +{ + if (empty($post_ids)) { + return array(); + } + $author_ids = array(); + foreach ($post_ids as $post_id) { + $post_authors = get_field('authors', $post_id); + if (empty($post_authors)) continue; + + foreach ($post_authors as $author) { + $author_id = is_object($author) ? $author->ID : (int) $author; + if ($author_id) { + $author_ids[$author_id] = $author_id; // set pour éviter les doublons + } + } + } + if (empty($author_ids)) { + return array(); + } + return get_posts(array( + 'post_type' => 'auteurs', + 'post__in' => array_values($author_ids), + 'posts_per_page' => -1, + 'orderby' => 'title', + 'order' => 'ASC', + )); +} \ No newline at end of file