From 9120e1111054165384554ae6f77ea63c5df29750 Mon Sep 17 00:00:00 2001 From: Jacson Passold Date: Fri, 24 Nov 2017 16:55:35 -0200 Subject: [PATCH] add support to insert with collection relation --- .../repositories/class-tainacan-repository.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/classes/repositories/class-tainacan-repository.php b/src/classes/repositories/class-tainacan-repository.php index 20d93d899..bfccc67da 100644 --- a/src/classes/repositories/class-tainacan-repository.php +++ b/src/classes/repositories/class-tainacan-repository.php @@ -36,8 +36,19 @@ abstract class Repository { } } - // save post and geet its ID - $obj->WP_Post->post_type = $obj::get_post_type(); + // If implement trait \Tainacan\Traits\Entity_Collection_Relation get its collection relation, else get post type from entity + if ( method_exists($obj, 'get_collection') ) { + $collection = $obj->get_collection(); + + if (!$collection){ + return false; + } + $cpt = $collection->get_db_identifier(); + $obj->WP_Post->post_type = $cpt; + } + else { + $obj->WP_Post->post_type = $obj::get_post_type(); + } $obj->WP_Post->post_status = 'publish'; // TODO verificar se salvou mesmo