avoid switch to default language when searching with qTranslate

When using the query-mode (the language is noted as an attached ‘?lang=en’ in the URL) a performed search shows the results in the default language (which could be the one selected in the browser settings, not the one chosen by a user).

The Solution:
Add the following to ‘Searchform.php’ in ‘design’ -> ‘Editor’
just in front of the ‘<\form>‘ tag:

<input type="hidden" name="lang" value="<?php echo qtrans_getLanguage(); ?>">

… this way the language-parameter will be added to the URL as a hidden field.

Source: http://stackoverflow.com/questions/8435113/wordpress-qtranslate-keep-dont-keep-lang-on-word-search

5 thoughts on “avoid switch to default language when searching with qTranslate

  1. I have similar problem, with my search link for my template.
    <button class="search" type="submit" id="searchsubmit" input type="hidden" name="lang" value="”>{$label}

    Or, this does not work like that?

    • Hey,

      it should work if you insert
      < ?php echo qtrans_getLanguage(); ?>
      as the value (like value = “< ?php echo qtrans_getLanguage(); ?>“). That line will output the currently selected language.

Leave a Reply

Your email address will not be published. Required fields are marked *