From b960848b23bdc5c3e5235f2aa1eff93373490622 Mon Sep 17 00:00:00 2001 From: mateuswetah Date: Fri, 5 Apr 2024 14:54:41 -0300 Subject: [PATCH] Fixes to handling of taxonomy metadata value in conditional sections. --- src/classes/entities/class-tainacan-item.php | 17 +++++++++++++---- .../components/edition/item-edition-form.vue | 6 +++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/classes/entities/class-tainacan-item.php b/src/classes/entities/class-tainacan-item.php index 4c01ef24b..765bf5381 100644 --- a/src/classes/entities/class-tainacan-item.php +++ b/src/classes/entities/class-tainacan-item.php @@ -1184,17 +1184,26 @@ class Item extends Entity { if ( $metadata_section->is_conditional_section() ) { $rules = $metadata_section->get_conditional_section_rules(); + if ( !empty($rules) ) { foreach ( $rules as $meta_id => $meta_values_conditional ) { $meta_values = []; $metadatum = new \Tainacan\Entities\Metadatum($meta_id); $metadatum_type = $metadatum->get_metadata_type_object(); + if ( $metadatum_type->get_primitive_type() == 'term' ) { $item_metadata = new \Tainacan\Entities\Item_Metadata_Entity($this, $metadatum); - $term_values = $metadatum->is_multiple() ? $item_metadata->get_value() : array( $item_metadata->get_value() ); - $meta_values = array_map(function($term) { - return $term->get_id(); - }, $term_values); + + if ( $metadatum->is_multiple() ) { + $term_values = $item_metadata->get_value(); + $meta_values = array_map(function($term) { + return $term->get_id(); + }, $term_values); + } else { + $term_values = $item_metadata->get_value(); + $meta_values = $term_values == false ? [] : $term_values; + } + } else { $item_id = $this->get_id(); $meta_values = get_post_meta( $item_id, $meta_id ); diff --git a/src/views/admin/components/edition/item-edition-form.vue b/src/views/admin/components/edition/item-edition-form.vue index f9c1c92cc..aa42fc978 100644 --- a/src/views/admin/components/edition/item-edition-form.vue +++ b/src/views/admin/components/edition/item-edition-form.vue @@ -397,7 +397,7 @@