fix: too check item post type to get collection

This commit is contained in:
vnmedeiros 2021-03-22 16:30:41 -03:00
parent 5444fa770a
commit 2e7365d73f
1 changed files with 10 additions and 0 deletions

View File

@ -36,6 +36,16 @@ trait Entity_Collection_Relation {
if($this->collection instanceof Entities\Collection){
return $this->collection;
}
} else {
$post_type = get_post($this->get_id())->post_type;
$matches = array();
$regex = '/' . Collection::$db_identifier_prefix . '([a-zA-Z0-9_]*)' . Collection::$db_identifier_sufix . '/';
preg_match($regex, $post_type, $matches);
$collection_id = $matches[1];
if (is_numeric($collection_id)) {
$this->set_collection_id($collection_id);
return $this->get_collection();
}
}
return null;