Guest User

Untitled

a guest
Feb 18th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. <?php
  2.  
  3. // …
  4.  
  5. function l10nFilterQuery($query)
  6. {
  7. $langs = [
  8. 'fr_FR',
  9. 'en_UK',
  10. ];
  11.  
  12. // Stop if the query is only for a category.
  13. if (1 === sizeof($query->query) && isset($query->query['category_name'])) {
  14. return;
  15. }
  16.  
  17. foreach ($langs as $currentLanguage) {
  18. if (USER_LANG !== $currentLanguage) {
  19. $excludedCategory = get_category_by_slug(
  20. strtolower($currentLanguage)
  21. );
  22. if ( false !== $excludedCategory ) {
  23. $excludedCategoryId = $excludedCategory->term_id;
  24. $query->query_vars['cat'] .= '-' . $excludedCategoryId;
  25. }
  26. }
  27. }
  28. }
  29. add_action('pre_get_posts', 'l10nFilterQuery', 10, 1);
Add Comment
Please, Sign In to add comment