Support » Plugin: Qtranslate Slug » Qtranslate slug and search

  • Hi,

    I’m having trouble with searching in different languages. There are solution posted for both my problems in this thread but they seem mutually exclusive to me. (one checks for isset(x) the other solution for !isset(x) )

    I tried both solutions and they fix their corresponding problem but when using them both, of course it won’t work so I either have no search in non-default language or no pagination.

    Maybe I’m doing something wrong but I just don’t see it so any help is appreciated.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Anyone also still having problems with search results pagination and/or search in the non-default language in combination with qtranslate-slug?

    I can either get pagination to work or serach in another language but not both at the same time. Solution are posted in the above thread and are as follows. One of them should be resolved according to the author with version 1.1 but for me it isn’t.

    One solution says replace some code with:

    if ( isset( $wp->matched_query ) && ! isset( $query[‘s’] ) )

    The other says insert this:

    return array(‘s’ => $query[‘s’]);

    Both solutions go in the same function, the one right after the other and obviously are not compatible with each other. My PHP knowledge is not sufficient to figure this one out.

    It’s one of the last things I need to resolve before publishing so any help is greatly appreciated.

    Thanks in advance.


    I have a wordpress blog using the qTranslate pluging with two langs activated.

    If I do a search under the URL it works correctly. But If I do a search with the URL[whatever lang code], it duplicate the lang code and move to a 404 page with URL:[langcode]/[langcode]/?s=something

    EX search: (WORK) (error 404) but try => (WORK) (error 404) => (WORK)

    I don’t know if this is a qTranslate bug or a problem with my .htaccess or what.

    Someone could help me with this?

    I am facing the same problem after installing qtranslate-slug plugin. Search page for second language is showing 404 error page as it is generating url

    For default language it is coming fine. Please help to make the right path for search query.

    the solution is,

    In the file qtranslate_hooks.php look this code (Line 216):

    function qtrans_fixSearchForm($form) {
    	$form = preg_replace('#action="[^"]*"#','action="'.trailingslashit(qtrans_convertURL(get_home_url())).'"',$form);
    	return $form;

    and replace for this

    function qtrans_fixSearchForm($form) {
    	$form = preg_replace('#action="[^"]*"#','action="'.get_home_url().'"',$form);
    	return $form;

    Hi maspiter, this works for me, added at the beginning of the function filter_request, (file: qtranslate-slug.php):

    function filter_request( $query ) {
    	global $q_config, $wp_query, $wp;
          // -> Search
          if(isset($query['s'])) {
    	$id = '';
    	$function = 'home_url';
            foreach( $q_config['enabled_languages'] as $lang ) {
    	     $this->lang = $lang;
       	     $this->current_url[$lang] = apply_filters('qts_url_args', call_user_func($function, $id));
    	 $this->lang = false;
             return array('s' => $query['s'],'paged'=> $query['paged']);
    //rest of code...

    I also had to add this one:



    I also had problems with the search bringing back my visitors to the default site language. To solve it, in the admin panel, i went to :

    Settings > Languages > Advanced Settings (click show)

    and under URL modification code, selected the option :
    Use Pre-Path Mode (Default, puts /en/ in front of URL)

    This way, all urls add the language slug right after the root url, and i can use <?php bloginfo('url'); ?> with anything i want after it in all my templates and the language always follows from one page to the other.

    It also works with the default WP search.

    Hope this helps!



    Great Carret! it works for me, it is a bit weird to see the language twice in the address “../en/en/?=….” but it is just aesthetic.
    I didnt use your final addition of the post 4022512 and worked. I dont know why.



    Hi elkiloprieto.

    If you did not, you must also add the zelti’s solution:

    That fix the duplicate of language code in the url.

    To not modify any file of qtranslate, add this code in functions.php theme file.

    remove_filter('get_search_form', 'qtrans_fixSearchForm',0);
    add_filter('get_search_form',	'qtrans_fixSearchForm_yop', 10, 1);
    function qtrans_fixSearchForm_yop($form) {
    //$form = preg_replace('#action="[^"]*"#','action="'.trailingslashit(qtrans_convertURL(get_home_url())).'"',$form);
    //qtranslate Slug compatibilidad, no duplicar en url idioma /es/es/ al buscar (search)
       $form = preg_replace('#action="[^"]*"#','action="'.trailingslashit(get_home_url()).'"',$form);
    	return $form;




    Perfecto!!! it is totally solved.

    No more 404, no duplicated languages on the URL
    Just one note, instead of qtranslate I used mqtranslate due the lack of new support and updates from qtranslate developer… but it is the same and work very well with qtranslate-slug.

    Bonus, if someone here use Advanced Custom Field (a must have!) plugin for multilanguage sites I recommend the ACF-qtranslate which allow custom fields with the qtranslate functionality.

    Gracias Carret.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Qtranslate slug and search’ is closed to new replies.