Skip Navigation

This thread is resolved. Here is a description of the problem and solution.

Problem:
When logged into the backend and viewing the front-end in a different browser tab, switching from the default language to another language and using an AJAX filter on a custom post type page results in displaying results from the default language instead of the selected language. This issue only occurs when logged in and is visible on the page with the AJAX filter, as two language cookies appear: one for the backend and one for the front-end, with the front-end cookie incorrectly switching to the admin language.

Solution:
First, confirm if the option "Store a language cookie to support language filtering for AJAX" is enabled in WPML → Languages. You can find more information about this setting here.

Next, check if the issue persists when all non-WPML related plugins are temporarily disabled. This helps determine if there's a conflict with other plugins.

If the problem continues, it may be due to compatibility issues between your custom code and WPML. While we cannot debug custom solutions directly, you can refer to our documentation on debugging theme compatibility here and the WPML Hooks Reference API here for guidance.

We also recommend testing this issue on an alternative server or local installation to rule out server settings as the cause. Additionally, keep an eye out for the upcoming beta version of WPML 4.6.10 and consider testing it.

If the solution provided here is not relevant to your case, either because it's outdated or not applicable, we highly recommend checking related known issues at https://wpml.org/known-issues/, verifying the version of the permanent fix, and confirming that you have installed the latest versions of themes and plugins. If you still need assistance, please do not hesitate to open a new support ticket in our forum.

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Tagged: 

This topic contains 5 replies, has 2 voices.

Last updated by Andrey 8 months ago.

Assisted by: Andrey.

Author Posts
March 19, 2024 at 2:49 pm #15426984

geertP

URL: eu.iko.com

Problem: We have a custom post type ‘Technical Data sheets’.
On the page where we show the Technical data sheets, the user can filter the data sheets based on division. The filter works with AJAX.

This all works fine, except in 1 case, when you are also logged in in the back-end.

Case: Logged in into the backend and you have the front-end in a different browser tab.
-> When you switch from the default language to another language AND you use the filter, you get to see results which do not belong to the chosen language. They belong to the default language.
We only experience this when we are logged in. Otherwise, everything works normal.

We have been searching for the cause and we can find the following problem, but we can’t solve it.

Chrome -> inspector -> Application -> Cookies -> Filter on WPML
Here we get to see the language cookie of the page.
In case we’re not logged in, you see the correct language cookie
In case you are logged in, you get to see 2 Language cookies:
1 of the back-end
1 of the front-end
When the page loads, you get to see that the front-end language cookies changes from the correct language to the admin language. This causes that it shows incorrect data on the page.

ATTENTION, this is only on the page where we use the Filter. On the other pages (also with custom page types) it looks like the cookies works as expected.

I’ve made a short video where I show it:
hidden link

March 19, 2024 at 7:55 pm #15428716

Andrey
Supporter

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kyiv (GMT+02:00)

Thank you for your explanation. Can you please confirm whether the option "Store a language cookie to support language filtering for AJAX" is enabled in WPML → Languages? Here is more information about it: https://wpml.org/documentation/getting-started-guide/language-setup/enabling-language-cookie-to-support-ajax-filtering/.

Also, can you check if the same issue occurs when you temporarily disable all non-WPML related plugins?

Additionally, could you please provide more details on how you created the filter on this page and how it functions? As I understand it, you have a custom-made theme.

March 20, 2024 at 7:34 pm #15433572

geertP

Hi,

I made a duplicate of the website on hidden link so we can test further without interrupting the live website.

The option "Store a language cookie to support language filtering for AJAX" is enabled. Which is a pitty, I hoped it would be that simple.

I've disabled all plugins except:
- Advanced Custom fields pro
- gravity forms
- WPML Multilingual CMS
- WPML String translation

Without the first 2 plugins, the website doesn't work because of our custom theme. The filter is also in our theme, so changing theme is not an option.

Regarding how we create the filter:
We have a custom post type 'documentation', this cpt has a couple of taxonomies: 'documentation type', 'division' & 'documentation category'.

We show on the page all the documentation with the documentation type: technical file.

The documentation posts are grouped by documentation category and those categories are grouped by division.
We made a filter to show documentation based on division.
When a division is checked, we do an ajax-call to get the filtered result.
In the back-end we do a wp-query to get the documentation based on the selected division(s).
When a user is logged in, this always returns the documentation posts from the default language. (as shown in first support request)
When a normal visitor (not logged in) uses this filter, it works as expected.

I can give you access to the back-end and even FTP/DB access if that is helpful. We have a test-environment now so we can test.

thanks in advance
Geert

March 21, 2024 at 10:03 pm #15438435

Andrey
Supporter

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kyiv (GMT+02:00)

Thank you for sharing your feedback with us. Based on the information you provided, compatibility issues between your custom code and WPML might exist. Please note that we cannot debug custom solutions as they fall outside the scope of our support provided in the support forum.

However, I suggest that you have a look at the common issue related to this problem, which you can find at https://wpml.org/documentation/support/debugging-theme-compatibility/#issue-custom-non-standard-wordpress-ajax-requests-always-return-the-default-language-content. Moreover, if you need more information about hooks, you can refer to the Hooks Reference API at https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference/.

Additionally, I recommend testing this issue on an alternative server or local installation to ensure server settings do not affect this behavior. Please note that we have a beta version of WPML 4.6.10 that will be available soon, and I suggest you test it as well.

March 22, 2024 at 8:10 am #15439149

geertP

Hi,

Thanks for your feedback. We will further investigate this.

If you have any idea in which direction we have to search, please share.

Further, this ticket can be closed for now.

Thanks for your time.

Geert

March 22, 2024 at 8:16 am #15439152

Andrey
Supporter

Languages: English (English ) Russian (Русский )

Timezone: Europe/Kyiv (GMT+02:00)

Thank you. These are the ideas I have already shared with you. They might be helpful for you in moving forward. Have a great weekend ahead.