我有多语言网络商店,并一起使用 WPML 插件和 Relevanssi 更好的搜索插件。
Relevanssi 插件有一个选项
将结果限制为当前语言:如果选中此选项,Relevanssi 将仅返回当前活动语言的结果。否则结果将包括每种语言的帖子。
问题是,在我选中此选项后,Relevanssi 更好的搜索插件不会以当前活动语言返回结果,而是仅以默认语言(在我的情况下为英语)返回结果。如果我不选中此选项,Relevanssi 更好的搜索插件会返回所有 3 种语言的结果!
这是 Relevanssi wpml 过滤器代码。也许有人知道如何处理此代码以获取当前活动语言的结果?!
Relevanssi 作者没有时间这样做:(
function relevanssi_wpml_filter($data) {
$use_filter = get_option('relevanssi_wpml_only_current');
if ('on' == $use_filter) {
//save current blog language
$lang = get_bloginfo('language');
$filtered_hits = array();
foreach ($data[0] as $hit) {
if (isset($hit->blog_id)) {
switch_to_blog($hit->blog_id);
}
global $sitepress;
if (function_exists('icl_object_id') && !function_exists('pll_is_translated_post_type')) {
if ($sitepress->is_translated_post_type($hit->post_type)) {
if ($hit->ID == icl_object_id($hit->ID, $hit->post_type, false, $sitepress->get_current_language())) $filtered_hits[] = $hit;
}
else {
$filtered_hits[] = $hit;
}
}
elseif (function_exists('icl_object_id') && function_exists('pll_is_translated_post_type')) {
if (pll_is_translated_post_type($hit->post_type)) {
global $polylang;
if ($polylang->model->get_post_language($hit->ID)->slug == ICL_LANGUAGE_CODE) {
$filtered_hits[] = $hit;
}
else if ($hit->ID == icl_object_id($hit->ID, $hit->post_type, false, ICL_LANGUAGE_CODE)) {
$filtered_hits[] = $hit;
}
}
else {
$filtered_hits[] = $hit;
}
}