facets endpoint - fix ordination in selected items (taxonomy)

This commit is contained in:
eduardohumberto 2018-09-13 23:35:32 -03:00
parent 9bcf796512
commit 74130c6bc0
1 changed files with 14 additions and 5 deletions

View File

@ -162,20 +162,29 @@ class REST_Facets_Controller extends REST_Controller {
if( $selected && $request['getSelected'] && $request['getSelected'] === '1' ){ if( $selected && $request['getSelected'] && $request['getSelected'] === '1' ){
$ids = $this->get_terms_ids( $terms ); $ids = $this->get_terms_ids( $terms );
$realResponse = [];
foreach( $selected as $index => $term_id ){ 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; continue;
} }
$term_selected = $this->terms_repository->fetch($term_id, $this->taxonomy); $realResponse[] = $term;
array_unshift($terms, $term_selected);
if( isset($request['number']) && ($index+1) >= $request['number']){ if( isset($request['number']) && count($realResponse) >= $request['number']){
break; break;
} }
} }
$terms = $realResponse;
} }
$restTermClass = new REST_Terms_Controller(); $restTermClass = new REST_Terms_Controller();