Search form
WordPress includes built in Search functionality, which WPML makes multilingual.
For this to work, two things are required in the search form:
- The form needs an ID of searchform.
- An input named lang must be set to the current language.
For example, this is the HTML from our own search form:
<form action="http://wpml.org/" id="searchform" method="get"> <input type="text" id="s" name="s" value=""/> <input type="submit" value="Search" id="searchsubmit"/> <input type="hidden" name="lang" value="en"/> </form>
The lang hidden input tells WPML that we’re searching in English. If it was set to ‘es’, it would mean we’re searching in Spanish.
Adding the language attribute to the search form
When the searchform ID is set for the form and the lang input exists, WPML limits the search to that language and shows the search results page in the correct language. You can try our own search in different languages and see the results.
WPML’s sitepress.js does this little magic. If your theme prevents this JS from loading, you can do it yourself by manually adding the lang input to search forms and setting its value to the ICL_LANGUAGE_CODE constant.
<input type="hidden" name="lang" value="<?php echo(ICL_LANGUAGE_CODE); ?>"/>
English
It does not work for me :S:S:S:S it still shows posts in both languages.
I checked your source AND the search-engine of this website and even the search-engine of this website does not work correctly. If I’m right, you’ve used above solution as well, but when I go to the German page and I’m searching for ‘test’, I still get English results. Even on my blog the solution as told above does not work, it’s very very very frustrating. That it shows the results of other languages is not the biggest problem, but in my sidebar I’ve used a custom query to show the latest 5 posts. On all pages this works fine, but when I use the search-engine, it starts showing translated posts. Can someone help me please??????
You’re right. I’m seeing this too. Checking now…
Any progress on this? I can confirm on my end that the search seems to be returning all languages – even with the language params that get passed in.
We found and fixed the bug and will have a developers version for testing soon. I’ll announce it in the blog.
I have the same issue…
Any idea when you can privide the fix?
It’s fixed already in the current development version:
http://wpml.org/2010/06/bugfix-release-wpml-1-7-9-rc1/
Thanks alot, works perfectly now!
I am using the latest version with wordpress 3.0 and custom types.The search displays results for all languages.Any help or ideas?
Try the bugfix version:
http://wpml.org/2010/06/default-language-other-than-english/
We’re going to make this an official release this week, after making a few more minor changes (which shouldn’t affect you).