From 4d0e2e534a0604a2e73ff9c8f9749ecbd56fbac1 Mon Sep 17 00:00:00 2001 From: vnmedeiros Date: Mon, 29 Jun 2020 11:46:22 -0300 Subject: [PATCH] add value on last_term --- src/classes/class-tainacan-elastic-press.php | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/classes/class-tainacan-elastic-press.php b/src/classes/class-tainacan-elastic-press.php index 9da38de6b..0df1fb7df 100644 --- a/src/classes/class-tainacan-elastic-press.php +++ b/src/classes/class-tainacan-elastic-press.php @@ -365,16 +365,21 @@ class Elastic_Press { $itemsRepo = \Tainacan\Repositories\Items::get_instance(); $items = $itemsRepo->fetch($args['items_filter'], $args['collection_id'], 'WP_Query'); $items_aggregations = $this->last_aggregations; //if elasticPress active + + $last_term = []; + if(isset($items_aggregations['last_term'])) { + $value = explode('.', $items_aggregations['last_term']); + $last_term = [ + 'value' => sizeof($value) > 1 ? $value[sizeof($value)-2] : $value[0], + 'es_term' => $items_aggregations['last_term'] + ]; + } return [ // 'total' => count($items_aggregations), // 'pages' => '0', //TODO get a total of pages - 'values' => isset($items_aggregations['values']) ? $items_aggregations['values'] : [] , - 'last_term' => isset($items_aggregations['last_term']) ? - [ - 'label' => explode('.', $items_aggregations['last_term'])[0], - 'es_term'=>$items_aggregations['last_term'] - ] : '' + 'values' => isset($items_aggregations['values']) ? $items_aggregations['values'] : [], + 'last_term' => $last_term ]; }