From 5c947839b57e5d95f6151aef808cc19eaad123a5 Mon Sep 17 00:00:00 2001 From: Antoine M Date: Fri, 17 Nov 2023 12:56:18 +0100 Subject: [PATCH] refactoring build function in api to return html template AND result_amounts --- includes/api.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/includes/api.php b/includes/api.php index 216f6c3..a03b823 100644 --- a/includes/api.php +++ b/includes/api.php @@ -150,7 +150,12 @@ function build_news_posts_feed_all($request) $html_template = ob_get_clean(); - $response = new WP_REST_Response($html_template); + $response_data = array( + 'html_template' => $html_template, + 'total_posts_found' => $newsPostsDatas->found_posts, + ); + + $response = new WP_REST_Response($response_data); $response->set_status(200); return $response; @@ -194,7 +199,14 @@ function build_news_posts_feed_per_type_id($request) $html_template = ob_get_clean(); - $response = new WP_REST_Response($html_template); + $response_data = array( + 'html_template' => $html_template, + 'total_posts_found' => $newsPostsDatas->found_posts, + ); + + + $response = new WP_REST_Response($response_data); + $response->set_status(200); return $response;