Guest User

Untitled

a guest
Mar 22nd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. function searchwp_polylang_include_only_current_language_posts( $relevantPostIds, $engine, $terms ) {
  2.  
  3. if ( isset( $engine ) ) {
  4. $engine = null;
  5. }
  6.  
  7. if ( isset( $terms ) ) {
  8. $terms = null;
  9. }
  10.  
  11. $post_ids = $relevantPostIds;
  12.  
  13. if ( function_exists( 'pll_current_language' ) && function_exists( 'pll_default_language' ) ) {
  14.  
  15. $currentLanguage = pll_current_language();
  16.  
  17. if ( false == $currentLanguage ) {
  18. $currentLanguage = pll_default_language();
  19. }
  20.  
  21. // get all posts in the current language
  22. $args_translated = array(
  23. 'nopaging' => true,
  24. 'post_type' => array('translated_post_type1', 'translated_post_type2'),
  25. 'post_status' => 'any',
  26. 'fields' => 'ids',
  27. 'tax_query' => array(
  28. array(
  29. 'taxonomy' => 'language',
  30. 'field' => 'slug',
  31. 'terms' => sanitize_text_field( $currentLanguage ),
  32. ),
  33. )
  34. );
  35.  
  36. $query_translated = new WP_Query( $args_translated );
  37. $post_ids_translated = $query_translated->posts;
  38.  
  39.  
  40. $args_untranslated = array(
  41. 'nopaging' => true,
  42. 'post_type' => array('untranslated_post_type1', 'untranslated_post_type2'),
  43. 'post_status' => 'any',
  44. 'fields' => 'ids',
  45. );
  46. $query_untranslated = new WP_Query( $args_untranslated );
  47. $post_ids_untranslated = $query_untranslated->posts;
  48.  
  49. $post_ids = array_merge( $post_ids_untranslated, $post_ids_translated );
  50. }
  51.  
  52. return $post_ids;
  53. }
  54.  
  55. add_filter( 'searchwp_include', 'searchwp_polylang_include_only_current_language_posts', 10, 3 );
Add Comment
Please, Sign In to add comment