Advertisement
msaari

relevanssi_wpml_filter

Jan 30th, 2014
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.42 KB | None | 0 0
  1. // thanks to rvencu
  2. function relevanssi_wpml_filter($data) {
  3.     $use_filter = get_option('relevanssi_wpml_only_current');
  4.     if ('on' == $use_filter) {
  5.         //save current blog language
  6.         $lang = get_bloginfo('language');
  7.         $filtered_hits = array();
  8.         foreach ($data[0] as $hit) {
  9.             if (isset($hit->blog_id)) {
  10.                 switch_to_blog($hit->blog_id);
  11.             }
  12.             global $sitepress;
  13.             if (function_exists('icl_object_id') && !function_exists('pll_is_translated_post_type')) {
  14.                 if ($sitepress->is_translated_post_type($hit->post_type)) {
  15.                     if ($hit->ID == icl_object_id($hit->ID, $hit->post_type,false,ICL_LANGUAGE_CODE))
  16.                         $filtered_hits[] = $hit;
  17.                 }
  18.                 else {
  19.                     $filtered_hits[] = $hit;
  20.                 }
  21.             }
  22.             elseif (function_exists('icl_object_id') && function_exists('pll_is_translated_post_type')) {
  23.                 if (pll_is_translated_post_type($hit->post_type)) {
  24.                     if ($hit->ID == icl_object_id($hit->ID, $hit->post_type,false,ICL_LANGUAGE_CODE))
  25.                         $filtered_hits[] = $hit;
  26.                 }
  27.                 else {
  28.                     $filtered_hits[] = $hit;
  29.                 }
  30.             }
  31.  
  32.             // if there is no WPML but the target blog has identical language with current blog,
  33.             // we use the hits. Note en-US is not identical to en-GB!
  34.             elseif (get_bloginfo('language') == $lang) {
  35.                 $filtered_hits[] = $hit;
  36.             }
  37.             if (isset($hit->blog_id)) {
  38.                 restore_current_blog();
  39.             }
  40.         }
  41.         return array($filtered_hits, $data[1]);
  42.     }
  43.     return $data;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement