Try it with this in your (child) theme’s functions.php
add_filter( 'related_posts_by_taxonomy_posts_clauses', 'rpbt_add_language_to_related_posts_query', 10, 4 );
function rpbt_add_language_to_related_posts_query( $pieces, $post_id, $taxonomies, $args ) {
global $wpdb;
// Check if WPML is activated
if ( ! defined( 'ICL_LANGUAGE_CODE' ) ) {
return $pieces;
}
// Check if WPML database table exists.
$table_name = "{$wpdb->prefix}icl_translations";
if ( $wpdb->get_var( "SHOW TABLES LIKE '$table_name'" ) != $table_name ) {
return $pieces;
}
$pieces['join_sql'] .= " INNER JOIN {$wpdb->prefix}icl_translations ON ($wpdb->posts.ID = {$wpdb->prefix}icl_translations.element_id)";
$pieces['where_sql'] .= " AND {$wpdb->prefix}icl_translations.language_code = '" . ICL_LANGUAGE_CODE . "'";
return $pieces;
}
I think this should do it, but I didn’t test it properly with the WPML plugin activated.
btw:
consider creating a child theme instead of editing your theme directly – if you upgrade the theme all your modifications will be lost. Or create a plugin with the code above.