fix: delete value of the compound metadata

This commit is contained in:
vnmedeiros 2022-02-23 12:03:59 -03:00
parent 710d900fc7
commit 7b3444efc1
1 changed files with 3 additions and 4 deletions

View File

@ -237,7 +237,7 @@ class Item_Metadata extends Repository {
$item_metadata->set_value([]); $item_metadata->set_value([]);
$this->save_terms_metadatum_value( $item_metadata ); $this->save_terms_metadatum_value( $item_metadata );
} elseif ( $metadata_type->get_primitive_type() == 'compound' ) { } elseif ( $metadata_type->get_primitive_type() == 'compound' ) {
$this->remove_compound_value($item_metadata->get_item(), $item_metadata->get_metadatum(), $item_metadata->get_parent_meta_id() ); $this->remove_compound_value($item_metadata->get_parent_meta_id() );
} else { } else {
delete_post_meta( $item_metadata->get_item()->get_id(), $item_metadata->get_metadatum()->get_id() ); delete_post_meta( $item_metadata->get_item()->get_id(), $item_metadata->get_metadatum()->get_id() );
} }
@ -249,8 +249,7 @@ class Item_Metadata extends Repository {
return $item_metadata; return $item_metadata;
} }
public function remove_compound_value(\Tainacan\Entities\Item $item, $metadatum, $parent_meta_id ) { public function remove_compound_value($parent_meta_id ) {
$post_id = $item->get_id();
$current_childrens = get_metadata_by_mid( 'post', $parent_meta_id ); $current_childrens = get_metadata_by_mid( 'post', $parent_meta_id );
if ( is_object( $current_childrens ) ) { if ( is_object( $current_childrens ) ) {
$current_childrens = $current_childrens->meta_value; $current_childrens = $current_childrens->meta_value;
@ -260,7 +259,7 @@ class Item_Metadata extends Repository {
$current_childrens = []; $current_childrens = [];
} }
foreach($current_childrens as $meta_children) { foreach($current_childrens as $meta_children) {
delete_post_meta('post', $meta_children); delete_metadata_by_mid('post', $meta_children);
} }
delete_metadata_by_mid('post', $parent_meta_id); delete_metadata_by_mid('post', $parent_meta_id);
return $current_childrens; return $current_childrens;