From d67b9c8291f1eb845bb4020081debc7e58ab0a39 Mon Sep 17 00:00:00 2001 From: Antoine M Date: Tue, 28 Nov 2023 17:33:12 +0100 Subject: [PATCH] modifying api to handle brochure building based on user current language --- includes/api.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/includes/api.php b/includes/api.php index 250c111..62f2116 100644 --- a/includes/api.php +++ b/includes/api.php @@ -56,6 +56,11 @@ add_action('rest_api_init', function () { 'methods' => 'GET', 'callback' => 'build_brochure_archive_rows', 'permission_callback' => '__return_true', + 'args' => array( + 'excluded_ids' => array( + 'sanitize_callback' => 'sanitize_text_field', + ), + ), )); // * BUILD FICHE INFOS ARCHIVE ROWS @@ -228,8 +233,12 @@ function build_news_posts_feed_per_type_id($request) return $response; } -function build_brochure_archive_rows() +function build_brochure_archive_rows(WP_REST_Request $request) { + $currentLanguage = $request->get_param('current-page-language') ?? 'fr'; + + do_action('wpml_switch_language', $currentLanguage); + $args = array( 'post_type' => 'brochures', 'posts_per_page' => -1, @@ -239,7 +248,6 @@ function build_brochure_archive_rows() 'meta_key' => 'brochure_pdf', 'meta_value' => '', 'meta_compare' => '!=', - // ICI METAQUERY FOR LE PDF ); $brochuresPosts = new WP_Query($args);