Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // …
- function l10nFilterQuery($query)
- {
- $langs = [
- 'fr_FR',
- 'en_UK',
- ];
- // Stop if the query is only for a category.
- if (1 === sizeof($query->query) && isset($query->query['category_name'])) {
- return;
- }
- foreach ($langs as $currentLanguage) {
- if (USER_LANG !== $currentLanguage) {
- $excludedCategory = get_category_by_slug(
- strtolower($currentLanguage)
- );
- if ( false !== $excludedCategory ) {
- $excludedCategoryId = $excludedCategory->term_id;
- $query->query_vars['cat'] .= '-' . $excludedCategoryId;
- }
- }
- }
- }
- add_action('pre_get_posts', 'l10nFilterQuery', 10, 1);
Add Comment
Please, Sign In to add comment