FEATURE Handling main authors in additions to author in buil posts query

This commit is contained in:
Antoine M 2026-03-20 16:55:48 +01:00
parent 7f6be681fe
commit f06fe21a5a

View File

@ -13,7 +13,6 @@ add_action('rest_api_init', function () {
'callback' => 'build_posts',
'permission_callback' => '__return_true',
));
});
@ -26,7 +25,7 @@ function build_posts($request)
$auteur = esc_html($request->get_param('auteur'));
$sort_by = esc_html($request->get_param('sort_by'));
$recherche = esc_html($request->get_param('recherche'));
// Construire les arguments de la query WordPress
$args = array(
@ -73,14 +72,20 @@ function build_posts($request)
);
}
// Filtre par auteur
// Filtre par auteur (authors = relation multiple, main_author = auteur principal)
if (!empty($auteur) && $auteur != '1') {
$args['meta_query'] = array(
'relation' => 'OR',
array(
'key' => 'authors', // Ajustez selon votre structure
'key' => 'authors',
'value' => '"' . $auteur . '"',
'compare' => 'LIKE',
),
array(
'key' => 'main_author',
'value' => $auteur,
'compare' => 'LIKE'
)
'compare' => 'LIKE',
),
);
}
@ -96,9 +101,9 @@ function build_posts($request)
ob_start();
if ($posts_query->have_posts()) :
while ($posts_query->have_posts()) : $posts_query->the_post();
get_template_part('template-parts/components/cards/post-card', null, array(
get_template_part('template-parts/components/cards/post-card', null, array(
'ID' => get_the_ID(),
));
));
endwhile;
else :
echo '<p>Aucun article trouvé.</p>';
@ -118,4 +123,3 @@ function build_posts($request)
return $response;
}