tomE-13
Background of the issue:
I have a "A different domain per language" installation with the following .TLD's: .nl (main), .de, .com.
When I navigate to the main language and click on the menu (top right corner), change language to English (bottom right corner), Close the menu (top right corner), Click on "Collection" in navigation, scroll down and click on "Floor- & wall tiles", scroll down and click on "Antique terracotta", I get the Dutch products. On the same page, when I switch the language to Deutsch, I get the correct products.
This is my Ajax request I've created to fetch the products:
```
$taxonomy,
'field' => $field,
'terms' => explode(',', $terms),
'operator' => $operator,
);
return $array;
}
function filterCount($catID, $taxonomy, $termID) {
$args = array(
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'categorie',
'field' => 'term_id',
'terms' => $catID,
'operator' => 'IN'
),
array(
'taxonomy' => $taxonomy,
'field' => 'term_id',
'terms' => $termID,
'operator' => 'IN'
),
)
);
$query = new WP_Query( $args );
return $query->post_count;
}
function fetch_products() {
$colors = esc_attr($_POST['color']);
$styles = esc_attr($_POST['style']);
$finishes = esc_attr($_POST['finish']);
$materials = esc_attr($_POST['material']);
$widths = esc_attr($_POST['width']);
$lengths = esc_attr($_POST['length']);
$heights = esc_attr($_POST['height']);
$lampTypes = esc_attr($_POST['typeLamp']);
$doorWindowTypes = esc_attr($_POST['typeDoorWindow']);
$maintenanceType = esc_attr($_POST['typeMaintenance']);
$categorie = esc_attr($_POST['category']);
$taxQuery = array('relation' => 'AND');
$showProducts = esc_attr($_POST['showProducts']);
if ($colors) {
array_push($taxQuery, create_tax_query_array('color', 'name', $colors, 'IN'));
}
if ($styles) {
array_push($taxQuery, create_tax_query_array('style', 'name', $styles, 'IN'));
}
if ($finishes) {
array_push($taxQuery, create_tax_query_array('finish', 'name', $finishes, 'IN'));
}
if ($materials) {
array_push($taxQuery, create_tax_query_array('material', 'name', $materials, 'IN'));
}
if ($widths) {
array_push($taxQuery, create_tax_query_array('width', 'name', $widths, 'IN'));
}
if ($lengths) {
array_push($taxQuery, create_tax_query_array('length', 'name', $lengths, 'IN'));
}
if ($heights) {
array_push($taxQuery, create_tax_query_array('height', 'name', $heights, 'IN'));
}
if ($lampTypes) {
array_push($taxQuery, create_tax_query_array('typeLamp', 'name', $lampTypes, 'IN'));
}
if ($doorWindowTypes) {
array_push($taxQuery, create_tax_query_array('typeDoorWindow', 'name', $doorWindowTypes, 'IN'));
}
if ($maintenanceType) {
array_push($taxQuery, create_tax_query_array('typeMaintenance', 'name', $maintenanceType, 'IN'));
}
if ($categorie) {
array_push($taxQuery, create_tax_query_array('categorie', 'term_id', apply_filters('wpml_object_id', $categorie, 'categorie'), 'IN'));
}
$args = array(
'post_type' => 'products',
'posts_per_page' => esc_attr($_POST['per_page']),
'offset' => esc_attr($_POST['offset']),
'tax_query' => $taxQuery,
'orderby' => 'menu_order',
'order' => 'ASC',
);
$query = new WP_Query($args);
$total = $query->found_posts;
$filters = [];
$data = new stdClass();
$products = [];
$totalProducts = 0;
$totalWebshopProducts = 0;
if ($query->have_posts()) :
while ($query->have_posts()): $query->the_post();
// create new object w/ post id, title url and image
$product = new stdClass();
$product->formType = get_field('formSelector');
$product->id = get_field('informatie')->code;
$product->reference = get_field('informatie')->reference;
$product->price = get_field('informatie')->price_info;
$product->title = get_the_title();
$product->url = get_the_permalink();
$product->imageSrc = get_field('image') !== null ? get_field('image')->sizes->w800 : '';
$product->imageSrcSet = get_field('image') !== null ? wp_get_attachment_image_srcset(get_field('image')->ID, 'w800') : '';
$product->imageSizes = get_field('image') !== null ? '(min-width: 1920px) 589px, (min-width: 1440px) 441px, (min-width: 1180px) 366px, (min-width: 768px) 238px, calc(100vw / 12 * 10)' : '';
$product->imageAlt = get_field('image') !== null ? get_field('image')->alt : '';
$totalProducts++;
if ($product->formType === 'order') {
$totalWebshopProducts++;
}
if ($showProducts === 'all') {
array_push($products, $product);
}
if ($showProducts === 'orderable') {
if ($product->formType === 'order') {
array_push($products, $product);
} else {
continue;
}
}
endwhile;
endif;
// get total of all products
$data->totalProducts = $totalProducts;
$data->totalWebshopProducts = $totalWebshopProducts;
$data->products = $products;
$data->filters = $filters;
$data->query = apply_filters('wpml_object_id', $categorie, 'categorie');
// return json object
echo json_encode($data);
die();
}
add_action( 'wp_ajax_fetch_products' , 'fetch_products' );
add_action( 'wp_ajax_nopriv_fetch_products', 'fetch_products' );
function my_acf_load_field( $field ) {
global $post;
$field['default_value'] = $post->ID;
return $field;
}
add_filter('acf/load_field/name=product_post_id', 'my_acf_load_field');
```
Symptoms:
Questions: