From 76578affa9babd21bd94dab41b9b4a8c7ffb97dd Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Fri, 31 Mar 2023 12:09:32 -0300 Subject: [PATCH] Lists all taxonomy metadata in tags list, even if from the same taxonomy from different collections. #778. --- .../class-tainacan-rest-items-controller.php | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/classes/api/endpoints/class-tainacan-rest-items-controller.php b/src/classes/api/endpoints/class-tainacan-rest-items-controller.php index 4ff4797b3..d82595e9e 100644 --- a/src/classes/api/endpoints/class-tainacan-rest-items-controller.php +++ b/src/classes/api/endpoints/class-tainacan-rest-items-controller.php @@ -434,27 +434,34 @@ class REST_Items_Controller extends REST_Controller { return $t != false ? $t->name : '--'; }, $terms_id); - $metas = $this->metadatum_repository->fetch(array( - 'meta_query' => [ - [ - 'key' => 'collection_id', - 'value' => empty($collection_id) ? 'default' : $collection_id, - 'compare' => '=' - ], - [ - 'key' => '_option_taxonomy_id', - 'value' => $taxonomy_id, - 'compate' => '=' - ] + $meta_query_params = [ + [ + 'key' => '_option_taxonomy_id', + 'value' => $taxonomy_id, + 'compate' => '=' ] + ]; + + if ( !empty($collection_id) && $collection_id !== 'default' ) { + $meta_query_params[] = [ + 'key' => 'collection_id', + 'value' => $collection_id, + 'compare' => '=' + ]; + } + + $metas = $this->metadatum_repository->fetch(array( + 'meta_query' => $meta_query_params ), 'OBJECT' ); - if( !empty($metas) ) { - $meta_query[] = array( - 'key' => $metas[0]->get_id(), - 'value' => $terms_id, - 'label' => $terms_name, - ); + if ( !empty($metas) ) { + foreach( $metas as $meta ) { + $meta_query[] = array( + 'key' => $meta->get_id(), + 'value' => $terms_id, + 'label' => $terms_name, + ); + } } }