Hello, jhow to do something like this with query language?
query: site.children.listed.filterBy('artist', '==', page);
…meaning: return all listed children who has this page in their ‘artist’ field (assuming that is a page selection field).
This probably boils down to if filterBy can deal with a $page in its comparison.
Thank you
No, you would have to use filterBy with a callable and that’s not possible in query language. So you need a custom method that returns the desired value and then use that method in your query.
Thank you,
What is wrong with this code ?
'allTheirProducts' => function () {
return $site->children()->listed()->filterBy('intendedtemplate','product')->filter(function ($p) {
return $p->artist()->toPage()->is($this);
});
},
I use it in a pagesdisplay field like this:
query: page.allTheirProducts;
…but I am getting the error:
The section “products” could not be loaded: Invalid query result - Result must be of type Kirby\Cms\Pages, Kirby\Cms\Field given.
Thanks
'allTheirProducts' => function () {
return site()->children()->listed()->filterBy('intendedtemplate','product')->filterBy(function($p) {
return $p->artist()->toPage() === $this;
});
},
Actually @texnixe , it still does not work.
I am getting the same error.
If I do this on home template:
dump(site()->children()->listed()->filterBy('intendedtemplate','product')->filter(function ($p) use ($page) {
return $p->artist()->toPage() === $page;
}));
… I get an empty Pages object as expected:
<pre>Kirby\Cms\Pages Object
(
)
</pre>
Why would pagesdisplay say a field is given instead?
Perhaps @rasteiner can help?
Thank you
Ok , I got it working.
Possibly some typo, although I can’t see what was it.
Thank you.