From 6469fedae1381957f20b6308676b624de2ecdf28 Mon Sep 17 00:00:00 2001 From: Mahfuz Date: Tue, 21 Oct 2025 12:54:27 +0600 Subject: [PATCH 1/2] Add a filter hook - directorist_listings_controller_orderby_options --- .../Version1/class-listings-controller.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/includes/rest-api/Version1/class-listings-controller.php b/includes/rest-api/Version1/class-listings-controller.php index ca45fa2746..4a0609f731 100644 --- a/includes/rest-api/Version1/class-listings-controller.php +++ b/includes/rest-api/Version1/class-listings-controller.php @@ -1475,7 +1475,18 @@ public function get_collection_params() { } protected function get_orderby_possibles() { - return array( + /** + * Filter the available "orderby" options used in the listings API schema and controller. + * + * This hook allows developers to modify or extend the enum values that define the orderby options + * for listing queries in the Directorist REST API. These options control how listings are sorted + * when fetched via API (e.g., by date, title, rating, etc.). + * + * @param array $orderby_options Array of allowed orderby values. + * + * @return array Modified list of orderby options. + */ + return apply_filter( 'directorist_listings_controller_orderby_options', array( 'id' => 'ID', 'include' => 'include', 'title' => 'title', @@ -1483,7 +1494,8 @@ protected function get_orderby_possibles() { // 'rating' => 'rating', 'popular' => 'popular', 'price' => 'price', - ); + 'rand' => 'rand', + ) ); } /** From 7f4a31d1a5895a1cdec99068987d390e6e6b3b39 Mon Sep 17 00:00:00 2001 From: Mahfuz Date: Tue, 21 Oct 2025 13:15:45 +0600 Subject: [PATCH 2/2] fix phpcs error --- .../Version1/class-listings-controller.php | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/includes/rest-api/Version1/class-listings-controller.php b/includes/rest-api/Version1/class-listings-controller.php index 4a0609f731..088cd92520 100644 --- a/includes/rest-api/Version1/class-listings-controller.php +++ b/includes/rest-api/Version1/class-listings-controller.php @@ -1486,16 +1486,19 @@ protected function get_orderby_possibles() { * * @return array Modified list of orderby options. */ - return apply_filter( 'directorist_listings_controller_orderby_options', array( - 'id' => 'ID', - 'include' => 'include', - 'title' => 'title', - 'date' => 'date', - // 'rating' => 'rating', - 'popular' => 'popular', - 'price' => 'price', - 'rand' => 'rand', - ) ); + return apply_filter( + 'directorist_listings_controller_orderby_options', + array( + 'id' => 'ID', + 'include' => 'include', + 'title' => 'title', + 'date' => 'date', + // 'rating' => 'rating', + 'popular' => 'popular', + 'price' => 'price', + 'rand' => 'rand', + ) + ); } /**