I tried the suggested function but it did not work for me. I expected to have the same top 10 regardless of language.
So, instead, I opted to add the following function at the end of top-10.php.
/**
* Returns the object identifier for the current language (WPML).
*/
function tptn_object_id_cur_lang( $post_id ) {
if ( function_exists( 'icl_object_id' ) ) {
return icl_object_id( $post_id, 'any', true, ICL_LANGUAGE_CODE );
} else {
return $post_id;
}
}
And replace the line that gets the $postid as indicated below.
/**
* Filter the post ID for each result. Allows a custom function to hook in and change the ID if needed.
*
* @since 1.9.8.5
*
* @param int $result->ID ID of the post
*/
$postid = tptn_object_id_cur_lang( apply_filters( 'tptn_post_id', $result->ID ) );
It would be great if you can find a way to include such a fix in the plugin to add support for WPML. Perhaps not exactly as I implemented it, but instead something that would be more generic.