• Resolved JuanMGonzalezR

    (@juanmgonzalezr)


    Hi, in my site i have custom query vars for some pages, like this:

    localhost/pagename/5

    where “5” is the value of the var

    when im in that link and i change the language the switcher redirect me to:

    localhost/paginanombre

    i want keep the value of the var like this

    localhost/paginanombre/5

    How can i do this?

    https://wordpress.org/plugins/polylang/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Chouby

    (@chouby)

    Hi!

    You will have to write your own translation link using the filter pll_translation_url.

    Thread Starter JuanMGonzalezR

    (@juanmgonzalezr)

    Can you give an example?

    Thread Starter JuanMGonzalezR

    (@juanmgonzalezr)

    Well Fixed! thank Chouby

    Here is my solution, i use pll_the_language_link

    and i cut the last two characters of the current link page, append to the url translate, and check if the current page is a page with the parameter

    here is the code:

    add_filter('pll_the_language_link', 'my_link', 10, 2);
    function my_link($url, $slug) {
    
    	$arr=array('pagename',
    		'nombrepagina',
    		'nomepágina',
    			);
    
    	foreach($arr as $a) {
            if (stripos($_SERVER['REQUEST_URI'],$a) !== false) {
            	return $url .substr($_SERVER['REQUEST_URI'], -2);
            	break;
            }
            else
            	return $url;
        }
    
    }
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Keep query string when change the language’ is closed to new replies.