From 9aa0ebc4aaa782f18b041f385e45d02a7c809ee9 Mon Sep 17 00:00:00 2001 From: Rafael Chaves Freitas Date: Thu, 7 May 2020 21:32:39 -0300 Subject: [PATCH 1/2] Parses the term_id as an integer in Elastic_Press class Sometimes the $term['key'] value is a numeric string, causing the method Tainacan\Repositories\Terms::fetch to return an array --- src/classes/class-tainacan-elastic-press.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/classes/class-tainacan-elastic-press.php b/src/classes/class-tainacan-elastic-press.php index c6fe14e45..f0fc97ce3 100644 --- a/src/classes/class-tainacan-elastic-press.php +++ b/src/classes/class-tainacan-elastic-press.php @@ -649,7 +649,7 @@ class Elastic_Press { $taxonomy_slug = $description_types[2]; $taxonomy_id = Repositories\Taxonomies::get_instance()->get_id_by_db_identifier($taxonomy_slug); foreach ($aggregation[$key]['buckets'] as $term) { - $term_id = $term['key']; + $term_id = intval($term['key']); $term_object = \Tainacan\Repositories\Terms::get_instance()->fetch($term_id, $taxonomy_slug); $count_query = $wpdb->prepare("SELECT COUNT(term_id) FROM $wpdb->term_taxonomy WHERE parent = %d", $term_id); $total_children = $wpdb->get_var($count_query); From 82f365d82064091c6612897ef23be60ce5c0f262 Mon Sep 17 00:00:00 2001 From: Rafael Chaves Freitas Date: Fri, 8 May 2020 15:35:44 -0300 Subject: [PATCH 2/2] Parses the term_id as an integer in Elastic_Press::format_aggregations_facet method --- src/classes/class-tainacan-elastic-press.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/classes/class-tainacan-elastic-press.php b/src/classes/class-tainacan-elastic-press.php index f0fc97ce3..01e2a4eb7 100644 --- a/src/classes/class-tainacan-elastic-press.php +++ b/src/classes/class-tainacan-elastic-press.php @@ -727,13 +727,13 @@ class Elastic_Press { $buckets = ($has_include == false ? $aggregation['buckets'] : $aggregation[$key]['buckets']); foreach ($buckets as $term) { if ($has_include) { - $term_id = $term['key']; + $term_id = intval($term['key']); $doc_count = $term['doc_count']; } else { - $term_id = $term['key'][$key]; + $term_id = intval($term['key'][$key]); $doc_count = $term['doc_count']; } - if ($term_id == '') continue; + if ($term_id === 0) continue; $term_object = \Tainacan\Repositories\Terms::get_instance()->fetch($term_id, $taxonomy_slug); $count_query = $wpdb->prepare("SELECT COUNT(term_id) FROM $wpdb->term_taxonomy WHERE parent = %d", $term_id);