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.

This topic contains 20 replies, has 2 voices.

Last updated by Benoit 1 year ago.

Assigned support staff: Yvette.

Author Posts
September 11, 2018 at 9:53 am

Benoit

I am trying to:
On this page hidden link (the FR translation of the original EN page*)
the "Theme" filter is built using get_terms() function with $theme->term_id as a <option> value. On click the value (theme ID) is passed to WP_Query via AJAX call to wp_ajax_nopriv_{custom_function} and wp_ajax_{custom_function} functions. There it is used in tax_query:
...
'tax_query' => array(
array(
'taxonomy' => 'event_theme',
'terms' => (int) $theme_id,
),
),

The problem is that the queried posts don't fall back to the original language (ENG) if none FR translation is created for the post as they do for the "Months" filter (that is built on a base of custom post field and not custom taxonomy).

* The page in the original language to compare functionality: hidden link

Link to a page where the issue can be seen:
hidden link

September 12, 2018 at 10:37 am #2727166

Yvette
Supporter

Languages: English (English ) Spanish (Español )

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

Hello

I visited the two links you provided and entered the same filter value as in your screenshots. However, for me, the two resulting pages look the same (see images)

Is this issue resolved already?

September 12, 2018 at 10:50 am #2727203

Benoit

Hello Yvette,

Thank you for your answer.

No my issue is not resolved already and I don't understand how you got that result? 🙂
I just tested again in all my browsers (logged and unlogged) and the error is still happening.

Is it a known issue or not?

September 12, 2018 at 11:13 am #2727230

Yvette
Supporter

Languages: English (English ) Spanish (Español )

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

Hello

I see now. I generated the two views that are identical when I was logged into the system. I just tried again and the same good results are given.

When I open an incognito session, the problem is then visible. I only use Chrome browsers.

So this seems to be about the function reading the WPML Ajax language cookie

I am not a programmer so I need to now ask - are you are the author of the "custom function" that you make reference to or is it some function delivered by a theme/plugin?

To my knowledge, there is no known issue here unless the function is not able to read the language cookie.

Thanks

September 12, 2018 at 11:39 am #2727297

Benoit

Thank you for trying again!

Yes I'm the author of this custom function. It doesn't come from a plugin/ theme.
Could you transfer this issue to a developper?

Thank you
Have a good day

September 12, 2018 at 12:03 pm #2727432

Yvette
Supporter

Languages: English (English ) Spanish (Español )

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

Unfortunately, I cannot transfer your ticket to anyone in development as our support policy focuses on fixing our own bugs/issues/WPML API. Custom solutions lies out of scope.

What I can do is advise on your code if you post it. I can also point you to resources that can help you.

We do not have any documentation on using WPML with Ajax for developers but if you use the standard WP AJAX mechanism (admin-ajax.php) and you enable the AJAX cookie in WPML -> Languages it all works without doing anything

If you use your own AJAX mechanism, you have to pass the language in the URL and set it with wpml_switch_language filter action
https://wpml.org/wpml-hook/wpml_switch_language/

I also found this forum thread which might be helpful for you too:
https://wpml.org/forums/topic/i-cant-get-posts-for-specific-language-using-admin-ajax-php-in-javascript/

Finally, if none of these resources works for you, I should refer you to our WPML Contractors for more help here;
https://wpml.org/contractors/

September 12, 2018 at 9:07 pm #2729058

Benoit

I tried to pass the language to the ajax function, but it didn't help.

The custom function is using default admin-ajax.php mechanism. Moreover, the same WP_Query in the same function works ok for the query based on post meta and doesn't work for the query based on post custom taxonomy.

Thanks

September 13, 2018 at 6:12 am #2730184

Yvette
Supporter

Languages: English (English ) Spanish (Español )

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

Ok - thanks for this additional information as it sounds like a possible bug with the API. I am going to search for any known issues with custom taxonomies and admin-ajax.php.

Could you post your code here or indicate where I can find it on your site? This will be helpful for the developers to see.

Kind regarrds

September 13, 2018 at 6:32 am #2730200

Benoit

Hello,

I can share the theme code via Bitbucket but I need the support email.
would that be possible?

Thank you

September 13, 2018 at 6:55 am #2730244

Yvette
Supporter

Languages: English (English ) Spanish (Español )

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

We normally cannot share our company email addresses.

You can place it in a file and use a file sharing system to then send a download link to us. I´m opening the private area for this.

Thanks

September 13, 2018 at 7:22 am
September 13, 2018 at 6:29 pm #2732658

Yvette
Supporter

Languages: English (English ) Spanish (Español )

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

Oh my.

What I was after was just the bit of code that has the custom function where the AJAX call is made for taxonomy terms.

I cannot read through all the files to find it.

You wrote: "...The custom function is using default admin-ajax.php mechanism. Moreover, the same WP_Query in the same function works ok for the query based on post meta and doesn't work for the query based on post custom taxonomy..."

So, please send these two examples that I can insert into a thme elike Twenty Seventeen to test.

Thanks.

September 14, 2018 at 11:18 am #2735215

Benoit

But I specified the files with the functions 🙁 The current functions are too complicated to separate from other website functionality for the example.

The developpers should figure out quickly if it's a problem related to WPML core features or not with the files I've provided, no?

Thank you for your help

September 16, 2018 at 1:54 pm #2738939

Yvette
Supporter

Languages: English (English ) Spanish (Español )

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

I don´t think I can get anyone to pick through your files and read/interpret the functions. This is simply out of our support scope.

I´ve gone another route and asked them for a small basic function that you can add to your theme to test if the admin-ajax mechanism is working with WPML for filters against custom taxonomies or not.

At least, in this way, you can know if the issue is with the mechanism or with your own code/solution.

I will update you once I have some feedback from my 2nd tier support group.

September 17, 2018 at 7:26 am #2739891

Benoit

Hello Yvette,
OK! Thanks anyway for looking for an "alternative" solution!
I'm waiting for your feedback.
have a good day