Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Wpml): get correct link for post type archive #15

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions classes/Compatibility/Wpml.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,23 +283,32 @@ public function getPostTypeLink(string $postLink, WP_Post $wpPost): string
return trailingslashit($postLink);
}

public function getPostTypeArchiveLink(string $link, string $post_type): string
public function getPostTypeArchiveLink(string $link, string $postType): string
{
$optionsReadingPostTypes = OptionsReadingPostTypes::getInstance()->getOptions();

if ($optionsReadingPostTypes === [] || $optionsReadingPostTypes === false) {
return trailingslashit($link);
}

$pageForArchiveId = $optionsReadingPostTypes[$post_type] ?? null;
$pageForArchiveId = $optionsReadingPostTypes[$postType] ?? null;

if ($pageForArchiveId === null) {
return trailingslashit($link);
}

$currentLanguage = apply_filters('wpml_current_language', null);

if ($optionsReadingPostTypes === [] || $optionsReadingPostTypes === false || empty($currentLanguage) || empty($currentLanguage)) {
if (empty($currentLanguage)) {
return trailingslashit($link);
}

$pageForArchiveUri = $this->getPageForArchiveUri($pageForArchiveId, $currentLanguage);
return trailingslashit(home_url($pageForArchiveUri)) ?: trailingslashit($link);
if ($pageForArchiveUri === '') {
return '';
}

return apply_filters('wpml_permalink', home_url($pageForArchiveUri), $currentLanguage);
}

public function setWpmlLsLanguageUrls(string $url, array $langs): string
Expand Down