diff --git a/src/classes/repositories/class-tainacan-metadata-sections.php b/src/classes/repositories/class-tainacan-metadata-sections.php index e9886beef..024ee903d 100644 --- a/src/classes/repositories/class-tainacan-metadata-sections.php +++ b/src/classes/repositories/class-tainacan-metadata-sections.php @@ -381,8 +381,10 @@ class Metadata_Sections extends Repository { $metadata_sections_ids = $this->fetch_ids(); $collection_metadata_sections_id = array_diff(array_map(function($el) {return $el->get_id();} , $this->fetch_by_collection($collection)), [\Tainacan\Entities\Metadata_Section::$default_section_slug]); - $args_exclude = array_merge( - array( + if ( empty($collection_metadata_sections_id) ) { + $not_post_ids = []; + } else { + $args_exclude = array( 'meta_query' => array( 'relation' => 'AND', array( @@ -398,10 +400,11 @@ class Metadata_Sections extends Repository { ) ) ) - ) - ); - $list_exclude = $metadata_repository->fetch_by_collection($collection, $args_exclude); - $not_post_ids = array_map(function($el) { return $el->get_id(); }, $list_exclude); + ); + + $list_exclude = $metadata_repository->fetch_by_collection($collection, $args_exclude); + $not_post_ids = array_map(function($el) { return $el->get_id(); }, $list_exclude); + } $args = array_merge( $args, @@ -416,10 +419,8 @@ class Metadata_Sections extends Repository { 'compare' => '=' ), array( - array( - 'key' => 'metadata_section_id', - 'compare' => 'NOT EXISTS' - ) + 'key' => 'metadata_section_id', + 'compare' => 'NOT EXISTS' ), array( 'key' => 'metadata_section_id',