Skip to content Skip to sidebar

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

This topic contains 3 replies, has 2 voices.

Last updated by darrellK 1 year, 10 months ago.

Author Posts
September 15, 2023 at 7:14 pm #14405289

darrellK

Hello,

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.

September 18, 2023 at 8:58 am #14410247

Dražen
Supporter

Languages: English (English )

Timezone: Europe/Zagreb (GMT+02:00)

Hello,

I checked and that is expected since your search result page is:

hidden link

that is not correct since you are using language per directory, it should go to:

hidden link

I would advise further checking your code with a developer who made the theme and making the necessary adjustments.

Hope this helps.

Regards,
Drazen

September 18, 2023 at 12:21 pm #14411721

darrellK

Hello Drazen,

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.

Any guidance would be greatly appreciated.

September 18, 2023 at 12:55 pm #14412089

darrellK

Hi Drazen,

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.