Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // thanks to rvencu
- 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,ICL_LANGUAGE_CODE))
- $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;
- }
- }
- // if there is no WPML but the target blog has identical language with current blog,
- // we use the hits. Note en-US is not identical to en-GB!
- elseif (get_bloginfo('language') == $lang) {
- $filtered_hits[] = $hit;
- }
- if (isset($hit->blog_id)) {
- restore_current_blog();
- }
- }
- return array($filtered_hits, $data[1]);
- }
- return $data;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement