Created
December 16, 2016 11:43
-
-
Save kricore/010ff9f9f8597c33ed3927c0620576d0 to your computer and use it in GitHub Desktop.
Filter the correct language on WordPress archive pages based on the lang $_GET param.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Language Detection | |
* @param $query, | |
* @uses pre_get_posts filter | |
* @return the modified query | |
*/ | |
function kdk_exclude_category( $query ) { | |
if ( ($query->is_tag() && $query->is_main_query()) || | |
($query->is_search() && $query->is_main_query()) || | |
($query->is_author() && $query->is_main_query()) || | |
($query->is_date() && $query->is_main_query())) | |
{ | |
// Get the $GET Param | |
if(isset($_GET["lang"])) | |
{ | |
$langcode = $_GET["lang"]; | |
$query->set( 'category_name', $langcode ); | |
} | |
return; | |
} | |
} | |
add_action( 'pre_get_posts', 'kdk_exclude_category' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This should be placed in your theme's functions.php file
The language code is the parent category (eg: en - de etc..) so we basically filter posts per category.