FEAT Ajout de la fonction renderRevueAuthorsGrid pour afficher les auteurs d'une revue

This commit is contained in:
Nonimart 2025-06-12 08:54:50 +02:00
parent e974ed0396
commit f94abb14b7

View File

@ -0,0 +1,47 @@
<?php
function renderRevueAuthorsGrid($revueID)
{
$revueRelatedArticles = new WP_Query(array(
'post_type' => 'articles',
'posts_per_page' => 3,
'orderby' => 'date',
'order' => 'DESC',
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'related_revue',
'value' => $revueID,
'compare' => '=',
),
),
));
$authors = array();
foreach ($revueRelatedArticles->posts as $article) {
$currentArticleAuthors = get_field('authors', $article->ID);
if (empty($currentArticleAuthors) || !is_array($currentArticleAuthors)) continue;
foreach ($currentArticleAuthors as $author) {
$authors[] = $author;
}
}
$authors = array_unique($authors);
ob_start();
foreach ($authors as $key => $author) {
get_template_part(
'template-parts/authors/card-author',
null,
array(
'ID' => $author->ID,
)
);
}
$grid_template = ob_get_clean();
return $grid_template;
}