Background of the issue:
I'm trying to get the URL to a term in a different language than the request language using the get_term_link() function. Even after changing the current language, the request language is used. The issue seems to be in the home_url_filter method, where the request language is used instead of the current language. Replacing $url_language = $this->get_request_language(); with $url_language = $this->sitepress->get_current_language(); seems to solve the issue when testing. I have tried both to set the current language with do_action('wpml_switch_language', $language_code); and $sitepress->switch_lang($language_code);. The result is the same.
Symptoms:
The get_term_link() function returns an invalid term URL prefixed with /pl/ (request language) resulting in a 404 error when visited, instead of a valid and correct URL prefixed with the current language (/no/) (or without the prefix when it's the the main language).
Questions:
Why does get_term_link() return a URL for the request language instead of the current language?
How can I ensure that get_term_link() returns a URL prefixed with the current language?
The topic ‘[Closed] get_term_link() only returns links for the request language, not the current language. The result is…’ is closed to new replies.
Manage Cookie Consent
We use cookies to optimize our website and services. Your consent allows us to process data such as browsing behavior. Not consenting may affect some features.
Functional
Always active
Required for our website to operate and communicate correctly.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
We use these to analyze the statistics of our site. Collected information is completely anonymous.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
These cookies track your browsing to provide ads relevant to you.