I am experiencing an issue using WordPress search, and when searching in a secondary language (United States), I get redirected to the default language (Canada) search results page.
For context, I am using the Language URL format - "Different languages in directories" setting. I also added the action to the search form within my theme file following this documentation - https://wpml.org/wpml-hook/wpml_add_language_form_field/.
To replicate the issue go to hidden link enter anything in the search and hit enter to go to the search results page. You will see that once you get to the results the language changes to Canada, the default, even though the &lang=us parameter is there. Is this because I use the "Different languages in directories" setting?
Any assistance to get this working would be appreciated.
Thank you for the follow-up. You are 100% correct, that is the issue I am experiencing.
My question is more how do I actually enforce the search results query page to append the /us/ when searching in the US language? I could not find anything in your documentation about configuring the form to work with language per directory, I only found the query parameter doc - https://wpml.org/wpml-hook/wpml_add_language_form_field/.
In our custom theme I had added some code to change the search query from ?s= to ?search= but even disabling that code block it still does not function as expected.
I figured out the issue after searching several sites and posts. The issue was that I had the form action parameter set to "/" instead of "<?PHP echo home_url() ?>". This now makes the search form lead to the correct language directory.
Manage Cookie Consent
We use cookies to optimize our website and services. Your consent allows us to process data such as browsing behavior. Not consenting may affect some features.
Functional
Always active
Required for our website to operate and communicate correctly.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
We use these to analyze the statistics of our site. Collected information is completely anonymous.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
These cookies track your browsing to provide ads relevant to you.