Created
January 27, 2017 19:23
-
-
Save ashiqur-rony/510e41031a2ecd68413d28965684c77f to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
/** | |
* Filter the URL to check if there is query string | |
* and attach the query string to WPML URL as well. | |
*/ | |
add_filter( 'icl_ls_languages', 'my_ls_filter' ); | |
function my_ls_filter($languages) { | |
global $icl_adjust_id_url_filter_off; | |
if( $_SERVER[ 'QUERY_STRING' ] ){ | |
if( strpos( basename( $_SERVER[ 'REQUEST_URI' ] ), $_SERVER[ 'QUERY_STRING' ] ) !== false ){ | |
foreach( $languages as $lang_code => $language ){ | |
if( is_post_type_archive() ) { | |
$query_string = $_SERVER['QUERY_STRING']; | |
$archived_taxonomy = get_queried_object(); | |
$archived_post_type = get_post_type(); | |
if( isset( $archived_taxonomy->slug ) ) { | |
$orig_flag_value = $icl_adjust_id_url_filter_off; | |
$icl_adjust_id_url_filter_off = true; | |
$translated_term = get_term( apply_filters( 'wpml_object_id', $archived_taxonomy->term_id, $archived_taxonomy->taxonomy, false, $lang_code ), $archived_taxonomy->taxonomy ); | |
$icl_adjust_id_url_filter_off = $orig_flag_value; | |
$query_string = str_replace($archived_taxonomy->taxonomy.'='.$archived_taxonomy->slug, $translated_term->taxonomy.'='.$translated_term->slug, $_SERVER["QUERY_STRING"]); | |
} | |
$languages[ $lang_code ]['url'] = apply_filters( 'wpml_permalink', get_post_type_archive_link( $archived_post_type ), $lang_code ) . '?' . $query_string; | |
} else { | |
$languages[ $lang_code ]['url'] = $languages[ $lang_code ]['url'] . '?' . $_SERVER["QUERY_STRING"]; | |
} | |
} | |
} | |
} | |
return $languages; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment