From 74130c6bc071c4146f8cbf9d5f40d8d566efb868 Mon Sep 17 00:00:00 2001 From: eduardohumberto Date: Thu, 13 Sep 2018 23:35:32 -0300 Subject: [PATCH] facets endpoint - fix ordination in selected items (taxonomy) --- .../class-tainacan-rest-facets-controller.php | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/api/endpoints/class-tainacan-rest-facets-controller.php b/src/api/endpoints/class-tainacan-rest-facets-controller.php index 8f6d6e182..d3cb43847 100644 --- a/src/api/endpoints/class-tainacan-rest-facets-controller.php +++ b/src/api/endpoints/class-tainacan-rest-facets-controller.php @@ -162,22 +162,31 @@ class REST_Facets_Controller extends REST_Controller { if( $selected && $request['getSelected'] && $request['getSelected'] === '1' ){ $ids = $this->get_terms_ids( $terms ); + $realResponse = []; foreach( $selected as $index => $term_id ){ - if( in_array($term_id,$ids) ){ + $term_selected = $this->terms_repository->fetch($term_id, $this->taxonomy); + $realResponse[] = $term_selected; + + } + + foreach( $terms as $index => $term ){ + + if( in_array($term->WP_Term->term_id,$selected) ){ continue; } - $term_selected = $this->terms_repository->fetch($term_id, $this->taxonomy); - array_unshift($terms, $term_selected); + $realResponse[] = $term; - if( isset($request['number']) && ($index+1) >= $request['number']){ + if( isset($request['number']) && count($realResponse) >= $request['number']){ break; } } - } + $terms = $realResponse; + } + $restTermClass = new REST_Terms_Controller(); }