I want to list products that in selected category.
Here my categories field as pages
type.
categories:
label: Categories
type: pages
multiple: true
And content file:
----
Categories:
- 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
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 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 now I understand much better @texnixe
Don’t be sorry, I love it!
1 Like