We have just released WPML 4.3.3. Before reporting issues please make sure to update - this version resolves all known issues with the major WPML 4.3 release

Hi, Amit here, I am the WPML Support Manager, our current ticket queue is high, update your WPML plugins and make sure you meet the minimal requirements for running WPML before reporting an issue please - many tickets are resolved doing that

Please look at our updated list of Known Issues and you can also use our support search to find helpful information and of course review our documentation before opening a ticket.

If you do need to open a ticket please make sure to provide us with all the needed information as described in this page

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 Bruno 1 month, 2 weeks ago.

Assigned support staff: Bruno.

Author Posts
September 24, 2019 at 3:08 pm #4632693

fabienR-3

I am trying to: filtering items by custom taxonomy, it works perfectly in default language but in other language (ie english) it is filtering in the default language too.
I tried to debug with some var_dump stuff and the parameter tax_query to get_posts function is OK, it uses the good term_id but the function return french items when it should return english items.

You can see the problem here : hidden link
When you click on "concierge" button just above items to filter you should have "Séjour parisien EN" showed, but this is french items that are displayed...

Here is my request in functions.php :

$taxonomie = $_POST['taxonomie'];

$args = array();

$args['tax_query'] = array();

if($taxonomie!="all"){
$args['tax_query'][] = array('taxonomy' => 'taxonomie_categorie_prestation', 'field' => 'term_id', 'terms' => $taxonomie);
}

$args['post_type']='prestation';
$args['posts_per_page']=-1;
$args['post_status']='publish';
$args['orderby']='menu_order';
$args['order']='ASC';
$args['suppress_filters']=false;

wp_reset_postdata();

$prestations = get_posts($args);

I also checked the checkbox "Stocker un cookie linguistique pour prendre en charge le filtrage de langue pour AJAX" in WPML parameters.

I really need help, thank you!

September 25, 2019 at 12:48 am #4634583

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Thank you for contacting us. From what I understand from your code inside each of these buttons you are using a taxonomy ID, correct?

For example, on the "Concierge" button, you are setting ID "15". I will attach a picture for you to see. In this case, are you already using this ID for the secondary language?

If this is not the secondary language taxonomy ID, please try changing your code in the first line:

$taxonomie = $_POST['taxonomie'];

To:

$taxonomie = apply_filters( 'wpml_object_id', $_POST['taxonomie'], 'taxonomie_categorie_prestation', true );

(wpml_object_id documentation: https://wpml.org/wpml-hook/wpml_object_id/)

If you make this change in code, do taxonomies return correctly?

Thank you.

September 25, 2019 at 3:09 am #4635195

fabienR-3

Hello,

Thank you for your answer. I already used the correct id for secondary language but I tried your solution. The problem is still there. I tried to debug with var_dump($taxonomie) after the apply_filter and this time $taxonomie return 12, not 15 (before your solution it returned 15) but as you can see with the attachment this taxonomy term is correctly translated in the back office. If I force the last argument of the apply_filter function to 'en' :

$taxonomie = apply_filters( 'wpml_object_id', $_POST['taxonomie'], 'taxonomie_categorie_prestation', true, 'en' );

this time $taxonomie has the correct value of 15 (see attachment with var_dump display) but the problem is still there with my get_posts function.

September 25, 2019 at 9:58 pm #4642127

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Hello,

Thank you for testing the steps above. Within the function you are retrieving the taxonomy, if you use the constant "ICL_LANGUAGE_CODE", which code is displayed?

If ICL_LANGUAGE_CODE returns null, you may need to pass the language code with the AJAX request before you can retrieve the locale into the function. That is, within the query, pass the current language so you can retrieve it within the AJAX function.

Thank you.

September 26, 2019 at 3:41 am #4643317

fabienR-3

Thank you for your answer but my deadline was very short and I had to try something else yesterday, so I don't do this with an AJAX request anymore, I just do some js script + CSS to hide/show correct items.

By the way, thank you for the tip, I will try it next time I have a similar problem.

September 26, 2019 at 6:19 pm #4649621

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

I'm glad you managed to solve the problem. Please, let me know if I can help with any other questions you may have about it. I'll be happy to help.

Thank you.