Forums Forums Search & Filter Pro Search & filter delete the lang parametre in url

Tagged: 

  • This topic has 9 replies, 3 voices, and was last updated 6 years ago by Anonymous.
Viewing 10 posts - 1 through 10 (of 10 total)
  • Anonymous
    #191273

    I have a problem on this page : https://ivea85-iveasas.pf6.wpserveur.net/references

    When I switch the page in German langage everything is fine. But then when I filter the page to display only one type of reference the page goes back to French.

    It’s a wordpress site and I manage the language with WEGLOT plugin.

    How can I fix this problem ?
    Thanks a lot

    Trevor
    #191276

    It would suggest that something is not translated. Whilst we do not have documentation for the weglot plugin, maybe the WPML documentation might help:

    https://searchandfilter.com/documentation/3rd-party/wpml/

    Or for Polylang:

    https://searchandfilter.com/documentation/3rd-party/polylang/

    In particular, the forms MUST be translated, but I see the same form (French) on both languages pages.

    Anonymous
    #191278

    Thanks Trevor, but when I switch in German for example the form is well translated and I can see the /de/ language tag in the URL but when I active the filter, Search & Filter erase the /de/ ?

    How should I do to keep the language tag in the URL ?

    Trevor
    #191280

    But the form itself is not translated, only the fields. I can clearly see that on both language pages, the form ID is 228, and it should not be. Does the plugin allow you to define/set which Post types are translated?

    Anonymous
    #191296

    “Does the plugin allow you to define/set which Post types are translated?”
    I don’t think it’s possible.

    I ask the WEGLOT support and he said to me: “Actually, the plugin Search & Filter Pro will refresh the page when you want to filter the results and automatically redirects to the original language. It would be necessary that you could change their code and take into account the language chosen to redirect towards the good version. You can go to our WordPress filters page to do this : https://developers.weglot.com/integration-guides/wordpress

    But I do not have the skills to add these filters. Is it possible to give me some help ?

    Trevor
    #191324
    This reply has been marked as private.
    Ross Moderator
    #191767
    This reply has been marked as private.
    Anonymous
    #191818

    Thank Trevor, no problems 😉

    I have an idea to make search and filter work with WEGLOT :
    WEGLOT has a function that store the current language in a variable :

    $current_and_original = weglot_get_current_and_original_language();
    echo $current_and_original[‘current’];

    So when I click on the filter button it would be necessary that search & filter adds in the URL the language stored in this variable. Maybe with the filter « Modify URL » : https://searchandfilter.com/documentation/action-filter-reference/


    function filter_function_name( $url, $sfid) {
    // Process URL here
    return $url;
    }
    add_filter( ‘sf_results_url’, ‘filter_function_name’, 10, 2 );

    So what i can add in place of // Process URL here I’m really a noob in dev 🙁

    Ross Moderator
    #192536

    Hi Jean-Francois

    So I had another look and I think I’ve found a quick fix.

    Rather than asking WEGLOT what the language is and doing something complicated, we can just choose to modify the results URL for your German search form only.

    This code should work but is untested:

    function modify_sf_results_url( $url,  $sfid ) {
    	
    	if($sfid===228){
    		//then we know the search form is the german search form (228), and we want to use the URL: /de/references
    		$url = home_url('de/references/');
    	}
    	
    	return $url;
    }
    add_filter( 'sf_results_url', 'modify_sf_results_url', 10, 2 );

    Let me know if that works, or if not, and I’ll take a look at what its doing.

    Thanks

    Anonymous
    #192563

    Thank you Ross! Now my code work perfectly.
    Here it is :

    function modify_sf_results_url( $url,  $sfid ) {
    
    	//We stock the current language in a variable
            $current_and_original = weglot_get_current_and_original_language();
    	$current_language = $current_and_original['current'];
            
            //If current language is German, we use the URL: /de/references
    	if($current_language == 'de'){
    		$url = home_url('de/references/');
    	}
    
    	return $url;
    }
    add_filter( 'sf_results_url', 'modify_sf_results_url', 10, 2 );

    Thank a lot for your help !

Viewing 10 posts - 1 through 10 (of 10 total)