From 7532a2f18b56fcccc3fb17309ef86a8e8ef80c49 Mon Sep 17 00:00:00 2001 From: Dan Lapteacru Date: Fri, 16 Dec 2022 16:03:24 +0200 Subject: [PATCH] Use same function for getting pageid for breadcrumbs --- src/Types/AbstractType.php | 29 ++++++++++++++++++++++++++--- src/Types/CustomPostType.php | 7 +------ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/src/Types/AbstractType.php b/src/Types/AbstractType.php index c517b89..40eebd9 100644 --- a/src/Types/AbstractType.php +++ b/src/Types/AbstractType.php @@ -56,16 +56,39 @@ public static function pageSelector(array $args) ); } + /** + * Get page ID for current model. + * + * @return int + */ public function getPageId(): int { if (null === $this->customPageId) { - $this->customPageId = (int) get_option("page_for_{$this->fieldName}", 0); + $this->customPageId = $this->getPageIdByPostType($this->fieldName); + } + + return $this->customPageId ?? 0; + } + + /** + * Get page ID by post type. + * + * @param string $postType + * @return int + */ + public function getPageIdByPostType(string $postType): int + { + $option = "page_for_{$postType}"; + if ('post' === $postType) { + $option = 'page_for_posts'; } + $pageId = (int) get_option($option, 0); + return apply_filters( 'itineris/page-as-post-type-archive/get_page_id', - ($this->customPageId ?? 0), - $this->fieldName + $pageId, + $postType ); } diff --git a/src/Types/CustomPostType.php b/src/Types/CustomPostType.php index c1efb01..84baeea 100644 --- a/src/Types/CustomPostType.php +++ b/src/Types/CustomPostType.php @@ -296,12 +296,7 @@ public function breadcrumbLinks(array $links): array $post_type = get_post_type(); - if ('post' === $post_type) { - $archive_page_id = (int) get_option('page_for_posts', 0); - } else { - $archive_page_id = (int) get_option("page_for_{$post_type}", 0); - } - + $archive_page_id = $this->getPageIdByPostType($post_type); if (0 === $archive_page_id) { return $links; }