diff --git a/includes/api.php b/includes/api.php index b5d8e4f..455c82d 100644 --- a/includes/api.php +++ b/includes/api.php @@ -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 '
Aucun article trouvé.
'; @@ -118,4 +123,3 @@ function build_posts($request) return $response; } -