2

When setting queries in the URL for posts on a page then changing the language by polylang plugin it resets the link and gets rid of the parameters and queries. The page is built on Wordpress on a custom theme I develop. ./en/projects/?tag_kem_en%5B%5D=three-springs gets changed to ./projekty/ I change the language with this code: pll_the_languages($args);

Tad
  • 73
  • 9

1 Answers1

8

You can include the query parameters by adapting the URL that Polylang provides though pll_the_languages().

I got it to work using this code snippet.

/**
 * Filter the translation url of the current page before Polylang caches it.
 *
 * @param null|string $url The translation url, null if none was found.
 */
function url_query_string( $url ) {
    if ( ! empty( $_SERVER['QUERY_STRING'] ) ) {
        return $url . '?' . $_SERVER['QUERY_STRING'];
    }
    return $url;
}
add_filter( 'pll_the_language_link', 'url_query_string' );

P.s Make sure to prefix the function or use namespaces.

grappler
  • 527
  • 5
  • 17