carhop__dynamiques-theme__P.../template-parts/authors/authors-last-publications.php
Nonimart 4c85c58127
All checks were successful
continuous-integration/drone/push Build is passing
FIX latest articles
2025-10-06 11:36:12 +02:00

51 lines
1.3 KiB
PHP

<?php
$postId = $args['postId'] ?? get_the_ID();
$authors = get_field('authors', $postId);
$isArticle = is_singular('articles');
if ($isArticle) {
$authors = get_field('authors', $postId);
} else {
$authors = getRevueAuthors($postId);
}
if (empty($authors)) return;
// Construire une meta_query avec OR pour chaque auteur
$meta_query = array('relation' => 'OR');
foreach ($authors as $author_id) {
$meta_query[] = array(
'key' => 'authors',
'value' => '"' . $author_id . '"', // Recherche la valeur sérialisée
'compare' => 'LIKE'
);
}
$authorsLastPosts = get_posts(array(
'post_type' => $isArticle ? 'articles' : 'revues',
'posts_per_page' => 6,
'orderby' => 'date',
'order' => 'DESC',
'meta_query' => $meta_query,
));
if (empty($authorsLastPosts) || count($authorsLastPosts) < 2) return;
?>
<div class="authors-last-publications">
<?php if (count($authors) <= 1) : ?>
<h3 class="title-small">Ses dernières publications</h3>
<?php else : ?>
<h3 class="title-small">Leurs dernières publications</h3>
<?php endif; ?>
<?php foreach ($authorsLastPosts as $post) : ?>
<?php get_template_part('template-parts/articles/card-article', null, array(
'ID' => $post->ID,
'showAuthors' => true,
)); ?>
<?php endforeach; ?>
</div>
<?php wp_reset_postdata(); ?>