filterBy method not working with pages field

I want to list products that in selected category.

Here my categories field as pages type.

    label: Categories
    type: pages
    multiple: true

And content file:



- laptop


I tried following syntax but not working. I missed something?

$page->children()->filterBy('categories', 'in', ['laptop']);

The filterBy() function doesn’t work here:

$page->children()->filter(function($child) {
  return $child->categories->toPages()->has(page('laptop'));
1 Like

Thank you :+1:

Added an example to document page, i hope that will be helpful.

1 Like

I think that example is a bit too specific in that place, I wanted to add a new recipe or add such example to the existing filtering compendium. It’s an example for the filter method, not for the users field.

Hmm :thinking: For what I see missing in the document, I just wanted to give an example of how to filter the pages with pages field.

I’m really sorry and it’s great that you contribute, @ahmetbora, but I think if we start adding examples for all types of use cases to the reference, it just get’s longer and harder to maintain.

For typical use cases, we have the cookbook.

Sorry about my kirby excitement :grimacing: now I understand much better @texnixe :+1:

Don’t be sorry, I love it!:heart_eyes:

1 Like