# Search function for multi-language sites

**URL:** <https://forum.getkirby.com/t/search-function-for-multi-language-sites/1099>\
**Category:** Questions\
**Tags:** v2\
**Created:** [May 18, 2015, 10:16am UTC](https://forum.getkirby.com/t/search-function-for-multi-language-sites/1099 "2015-05-18T10:16:30Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![gimesi](https://avatars.discourse-cdn.com/v4/letter/g/7ba0ec/32.png) [@gimesi](https://forum.getkirby.com/u/gimesi)\
**Post date:** [May 18, 2015, 10:16am UTC](https://forum.getkirby.com/t/search-function-for-multi-language-sites/1099/1 "2015-05-18T10:16:31Z")

</div>

Hi. I’m new to Kirby and I’m just trying to figure some things out.

First, congrats! I had a multi-language test site up and running like a charm in under 5 minutes… Then I added a search function, which also works, **but only** for the English site (English is set as standard language).

i.e. When I have one page open in another language and start a search, it throws back a “no results for …”.

Is there a way that Kirby (1) loops through **all** languages and shows the results, or (2) only returns results of the currently active language?

(By the way… Does this affect also tag functionality for a blog in multiple languages? I haven’t tried it yet…)

Thanks for your hints, links, solutions!

---

<div class="post-metadata">

**Author:** ![JulienS](https://avatars.discourse-cdn.com/v4/letter/j/c89c15/32.png) [@JulienS](https://forum.getkirby.com/u/JulienS)\
**Post date:** [October 27, 2015, 2:49pm UTC](https://forum.getkirby.com/t/search-function-for-multi-language-sites/1099/2 "2015-10-27T14:49:05Z")

</div>

Hi,

I have the same problem with a multi-language search function.

```
$site->index()->visible()->search($query, 'title|text'); 

```

How can I filter the current language before pagination?

Thank you very much!

Julien

---

<div class="post-metadata">

**Author:** ![JulienS](https://avatars.discourse-cdn.com/v4/letter/j/c89c15/32.png) [@JulienS](https://forum.getkirby.com/u/JulienS)\
**Post date:** [October 27, 2015, 3:46pm UTC](https://forum.getkirby.com/t/search-function-for-multi-language-sites/1099/3 "2015-10-27T15:46:29Z")

</div>

This is what I learned from user FabianSperrle:

```
foreach ($page->children()->filterBy('languages', $site->language()->code(), ',') as $child) {

```

Source: [Filter child pages by available translations](https://forum.getkirby.com/t/filter-child-pages-by-available-translations/351/5?u=juliens)

Where do I find out what can be filtered by filterBy function? The example above is not mentioned in the docs.  
Is this a working example? Sadly, it does not work for me when applying the filterBy function to foreach function.

I also tried to filter after index()

```
$results = $site->index()->filterBy('languages', $site->language()->code(), ',')->visible()->search($query, 'title|text');

```

but did not succeed.

EDIT: I now understand that this example of FabianSerrle only works when adding custom fields to the text files.  
Is there any other way to filter by language? This should be a basic function of a CMS, I guess.

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [October 27, 2015, 6:48pm UTC](https://forum.getkirby.com/t/search-function-for-multi-language-sites/1099/4 "2015-10-27T18:48:16Z")

</div>

You could use a custom filter like this:

> [@Prevent Default Language](https://forum.getkirby.com/t/prevent-default-language/2024/2):
>
> $articles = $page-\>children()-\>visible()-\>filter(function($child) {  
> return site()-\>language()-\>code() == $child-\>language()-\>code();  
> });

---

<div class="post-metadata">

**Author:** ![lukasbestle](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/lukasbestle/32/11437_2.png) [@lukasbestle](https://forum.getkirby.com/u/lukasbestle)\
**Post date:** [October 27, 2015, 9:47pm UTC](https://forum.getkirby.com/t/search-function-for-multi-language-sites/1099/5 "2015-10-27T21:47:15Z")

</div>

The `filterBy` method can filter by basically everything you can call as method on a page, be it a field or something like `url()`.

---

<div class="post-metadata">

**Author:** ![JulienS](https://avatars.discourse-cdn.com/v4/letter/j/c89c15/32.png) [@JulienS](https://forum.getkirby.com/u/JulienS)\
**Post date:** [October 28, 2015, 1:04pm UTC](https://forum.getkirby.com/t/search-function-for-multi-language-sites/1099/6 "2015-10-28T13:04:05Z")

</div>

That’s interesting! I did not know there is another filter method besides filterBy. This one gives me the opportunity to create my own “comparator”…

I will try this soon.

Thank you for your help! 😄

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [October 28, 2015, 1:12pm UTC](https://forum.getkirby.com/t/search-function-for-multi-language-sites/1099/7 "2015-10-28T13:12:29Z")

</div>

But this time it’s even in the docs: [http://getkirby.com/docs/cheatsheet/pages/filter](http://getkirby.com/docs/cheatsheet/pages/filter)

---

<div class="post-metadata">

**Author:** ![JulienS](https://avatars.discourse-cdn.com/v4/letter/j/c89c15/32.png) [@JulienS](https://forum.getkirby.com/u/JulienS)\
**Post date:** [October 28, 2015, 1:14pm UTC](https://forum.getkirby.com/t/search-function-for-multi-language-sites/1099/8 "2015-10-28T13:14:17Z")

</div>

Great, I will try this! Thank you!

---

<div class="post-metadata">

**Author:** ![JulienS](https://avatars.discourse-cdn.com/v4/letter/j/c89c15/32.png) [@JulienS](https://forum.getkirby.com/u/JulienS)\
**Post date:** [November 1, 2015, 4:20pm UTC](https://forum.getkirby.com/t/search-function-for-multi-language-sites/1099/9 "2015-11-01T16:20:20Z")

</div>

Hi texnixe,

I still have an issue with understanding

```
$child->language()->code()

```

Is language() returning a native attribute of the child page or just the function to retrieve the custom language field I have to use in my text file?

The filter method you mentioned only works when explicitly adding a custom field named “language” to the text file.

Isn’t there a way to easily filter by file name ending? (like \*.en.txt or \*.de.txt). I would expect this kind of filter to be included as it already has to be used by the core itself!?

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [November 9, 2015, 6:24pm UTC](https://forum.getkirby.com/t/search-function-for-multi-language-sites/1099/10 "2015-11-09T18:24:28Z")

</div>

Yes, the code above requires a special language field.

Otherwise you have to use a custom filter that checks if the page is available in the respective language, like in the switch example: [Language switcher example creating invalid URLs for missing translations](https://forum.getkirby.com/t/language-switcher-example-creating-invalid-urls-for-missing-translations/2420/9)

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 5:04pm UTC](https://forum.getkirby.com/t/search-function-for-multi-language-sites/1099/11 "2025-02-06T17:04:15Z")

</div>

Archived on February 6, 2025, 5:04pm UTC


