WordPress.org

Ready to get started?Download WordPress

Forums

Qtranslate Slug
Qtranslate slug and search (10 posts)

  1. maspiter
    Member
    Posted 1 year ago #

    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.

    http://wordpress.org/extend/plugins/qtranslate-slug/

  2. maspiter
    Member
    Posted 1 year ago #

    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:

    if(isset($query['s'])){
    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.

  3. cmerlo
    Member
    Posted 10 months ago #

    Hi!

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

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

    EX search:

    mypage.com/?s=a (WORK)
    mypage.com/en/?s=a (error 404) but try => mypage.com/en/en/?=a (WORK)
    mypage.com/de/?=a (error 404) => mypage.com/de/de/?=a (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?

  4. neha_seth
    Member
    Posted 10 months ago #

    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 mysite.com/en/en/?s=dfsdfsdf

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

  5. zelti
    Member
    Posted 9 months ago #

    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;
    }
  6. Carret
    Member
    Posted 9 months ago #

    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:
    http://wordpress.org/support/topic/pagination-issue-with-qtranslate?replies=9#post-4022512

  7. olivierlarochelle
    Member
    Posted 5 months ago #

    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!

  8. elkiloprieto
    Member
    Posted 5 months ago #

    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.

  9. Carret
    Member
    Posted 5 months ago #

    Hi elkiloprieto.

    If you did not, you must also add the zelti's solution:
    http://wordpress.org/support/topic/qtranslate-slug-and-search?replies=8#post-4772128

    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;
    }

    Saludos.

  10. elkiloprieto
    Member
    Posted 5 months ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic