Background of the issue:
I am encountering an issue with WPML where, if a product is published in the default language 'en' and has a translation in 'en-us' that is currently in 'draft' status, WPML still tries to generate a link in 'en-us' instead of falling back to the 'en' version. The code I am using is: $defaultLocale = apply_filters('wpml_default_language', null); return apply_filters('wpml_permalink', get_the_permalink(20), $defaultLocale). Link to a page where the issue can be seen: hidden link.
Symptoms:
When I try to retrieve the link for this product while the site is set to 'en-us,' WPML returns a URL with the 'en-us' prefix (e.g., hidden link), even though the 'en-us' version is not published. I expected to see: hidden link. Instead, I got: hidden link.
Questions:
How can I adjust the fallback logic to ensure WPML provides the link to the 'en' version when the 'en-us' translation is in 'draft' status?
Here is the forum ticket. I would like to request temporary access (wp-admin and FTP) to your site so I can take a better look at the issue. It would be better to have a testing site where the issue is replicated. Your next reply is set to private to share the info.
❌ IMPORTANT: Please backup your database and website before proceeding ❌
You can use this plugin to create the backup: https://wordpress.org/plugins/duplicator/
✙ I would need your permission to de-activate and re-activate Plugins and the Theme to change configurations on the site if needed. This is also a reason the backup is critical.
I would like to request temporary access (wp-admin and FTP) to your site so I can take a better look at the issue. It would be better to have a testing site where the issue is replicated. Your next reply is set to private to share the info.
❌ IMPORTANT: Please backup your database and website before proceeding ❌
You can use this plugin to create the backup: https://wordpress.org/plugins/duplicator/
✙ I would need your permission to de-activate and re-activate Plugins and the Theme to change configurations on the site if needed. This is also a reason the backup is critical.
If some one technical can answer it will be perfect
The problem comes from "get_the_permalink" function and "wpml_permalink" filter.
The "get_the_permalink" will return the product in the current language "en-us"
If the product in "en-us" is in Draft mode, it will return the preview URL and the filter "wpml_permalink" will just replace the language so we will get the preview URL.
The "wpml_permalink" must detect if the url is a preview URL, if yes, it should return the correct value for the translation, or we should get the ability to edit it with a parameter
I've tried to replicate the issue on a clean WordPress installation and confirmed the issue. This happens when the option auto adjust ID is enabled, you can go to WPML > Languages > Disable option "Adjust IDs for multilingual functionality" and recheck this.
Please check the attached screenshot and the sample code below:
$permalink = get_the_permalink( 100 ); // 100 is the translation post ID
echo "Permalink: " . $permalink;
echo "<br>";
$wpml_permalink = apply_filters( 'wpml_permalink', $permalink, 'fr' );
echo "WPML Permalink: " . $wpml_permalink;
If you want to test, please click this link hidden link
to access the sandbox site admin area.
The code is added to the theme folder > template-parts/content/content-page.php
After checking it internally with our team, disabling this option causes some issues, I will back soon to provide more information, I am waiting an answer from some people