Advertisement
Guest User

polylang support for relevanssi

a guest
Feb 3rd, 2014
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 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. global $polylang;
  25. if($polylang->model->get_post_language($hit->ID)->slug == ICL_LANGUAGE_CODE){
  26. $filtered_hits[] = $hit;
  27. }
  28. else if ($hit->ID == icl_object_id($hit->ID, $hit->post_type,false,ICL_LANGUAGE_CODE)){
  29. $filtered_hits[] = $hit;
  30. }
  31. }
  32. else {
  33. $filtered_hits[] = $hit;
  34. }
  35. }
  36.  
  37. // if there is no WPML but the target blog has identical language with current blog,
  38. // we use the hits. Note en-US is not identical to en-GB!
  39. elseif (get_bloginfo('language') == $lang) {
  40. $filtered_hits[] = $hit;
  41. }
  42. if (isset($hit->blog_id)) {
  43. restore_current_blog();
  44. }
  45. }
  46. return array($filtered_hits, $data[1]);
  47. }
  48. return $data;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement