Skip to content

Commit 71a4a5e

Browse files
authored
Merge pull request #15 from timohubois/fixWpmlPostArchiveLinks
fix(Wpml): get correct link for post type archive
2 parents 76b1ec7 + 4f932cb commit 71a4a5e

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

classes/Compatibility/Wpml.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,23 +283,32 @@ public function getPostTypeLink(string $postLink, WP_Post $wpPost): string
283283
return trailingslashit($postLink);
284284
}
285285

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

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

294-
$pageForArchiveId = $optionsReadingPostTypes[$post_type] ?? null;
294+
$pageForArchiveId = $optionsReadingPostTypes[$postType] ?? null;
295+
296+
if ($pageForArchiveId === null) {
297+
return trailingslashit($link);
298+
}
299+
295300
$currentLanguage = apply_filters('wpml_current_language', null);
296301

297-
if ($optionsReadingPostTypes === [] || $optionsReadingPostTypes === false || empty($currentLanguage) || empty($currentLanguage)) {
302+
if (empty($currentLanguage)) {
298303
return trailingslashit($link);
299304
}
300305

301306
$pageForArchiveUri = $this->getPageForArchiveUri($pageForArchiveId, $currentLanguage);
302-
return trailingslashit(home_url($pageForArchiveUri)) ?: trailingslashit($link);
307+
if ($pageForArchiveUri === '') {
308+
return '';
309+
}
310+
311+
return apply_filters('wpml_permalink', home_url($pageForArchiveUri), $currentLanguage);
303312
}
304313

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

0 commit comments

Comments
 (0)