acfViewData = $acfViewData->getDeepClone(); $this->acfCardData = $acfCardData->getDeepClone(); $this->posts = []; } public function getPostIdByUniqueId(string $uniqueId, string $postType): ?int { if (!is_numeric($uniqueId)) { if (false === strpos($uniqueId, '_')) { $prefix = ViewsCpt::NAME === $postType ? 'view_' : 'card_'; $uniqueId = $prefix . $uniqueId; } $query = new WP_Query([ 'post_type' => $postType, 'post_name__in' => [$uniqueId], 'posts_per_page' => 1, ]); $post = $query->get_posts()[0] ?? null; } // keep back compatibility for direct postIds (for shortcodes that were already pasted) else { $post = get_post($uniqueId); } if ($post && in_array($post->post_type, [$postType,], true) && 'publish' === $post->post_status ) { return $post->ID; } return null; } public function getAcfViewData(int $viewId): ViewData { if (key_exists($viewId, $this->posts)) { return $this->posts[$viewId]; } $acfViewData = $this->acfViewData->getDeepClone(); $acfViewData->loadFromPostContent($viewId); $this->posts[$viewId] = $acfViewData; return $acfViewData; } public function getAcfCardData(int $cardId): CardData { if (key_exists($cardId, $this->posts)) { return $this->posts[$cardId]; } $acfCardData = $this->acfCardData->getDeepClone(); $acfCardData->loadFromPostContent($cardId); $this->posts[$cardId] = $acfCardData; return $acfCardData; } }