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 Rohan Sadanandan 3 weeks, 4 days ago.

Assigned support staff: Rohan Sadanandan.

Author Posts
September 20, 2019 at 1:42 am #4608561

patrickL-43

I am trying to: use an ajax call to display products and have the language match

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

I expected to see: Spanish Products

Instead, I got: English Products

September 20, 2019 at 5:37 am #4609905

Rohan Sadanandan
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello,

Thank you for contacting WPML Support.

Please go to WPML > Languages and scroll down to the “Language filtering for AJAX operations” section. Please check the option to "Store a language cookie to support language filtering for AJAX". Then log out, clear your browser cache, and log back in.

Please let me know if this does not resolve the issue for you and I will take another look.
Also, I request you to update all the WPML plugins to the latest version.

Thanks,
Rohan

September 20, 2019 at 6:01 pm #4614031

patrickL-43

Hello, thank you for your response.

Yes, I checked that option yesterday when I was browsing through support forums here. That unfortunately did not help, neither did the 'surpress_filter' options, I tried '0', '1', 'true' and 'false'.

Here is my loop:

if(!empty($_POST["cat_slug"])){
$curr_cat = $_POST['cat_slug'];
}else{
$curr_cat = 'carton-sealers';
}

$new_query = array(
'relation' => 'AND',
$conditions
);

$args = array(
'posts_per_page' => -1,
'post_type' => 'product',
'suppress_filters' => 2,
'tax_query' => array(
array (
'taxonomy' => 'product-category',
'field' => 'slug',
'terms' => $curr_cat,
)
),
'orderby' => 'menu_order',
'order' => 'ASC',
'paged' => $page_num,
'meta_query' => $new_query
);
$the_query = new WP_Query( $args );

September 23, 2019 at 6:38 am #4620681

Rohan Sadanandan
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello,

Thanks for your patience & sorry for the delay.

I was just checking your code & it seems that you are fetching the products based on the terms "$curr_cat"
Could you please confirm that the translation of the term exists & you are passing the correct value in the $curr_cat variable?

Thanks,
Rohan

September 25, 2019 at 9:01 pm #4642051

patrickL-43

Yes, there are direct translations for each product category, I have also tried hardcoding my category ID, using the English and Spanish options.

No matter what I call, the english products display.

September 26, 2019 at 11:27 am #4646283

Rohan Sadanandan
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello,

Thanks for the details.

Could you please test in a minimal environment by disabling all plugins that are unrelated to WPML and switch to one of the default themes e.g. Twenty Fifteen, Do you see the same issue?
If the custom post type you are querying is created by either a plugin or a theme please leave them on. This will allow us to test if there are any other filter hooks manipulating the query.

Also, can you confirm if the "product" post type is configured to use a fallback language? This configuration can be found here: https://wpml.org/documentation/translating-your-contents/displaying-untranslated-content-on-pages-in-secondary-languages/

Thanks,
Rohan

The topic ‘[Closed] When using AJAX to Query posts, it only shows default language products’ is closed to new replies.