Pages field query listed and draft pages

In a Pages field I’m trying to select drafts from Services and listed pages from Projects section, something like this:

query: site.index(true).pages.filterBy("template","in",["service","project"])

Returns the listed Project template items, only.
How do I also get the drafts with the Service template (Services section)?
(k 3.3.4.)

The pagesthingy in there doesn’t make sense.
Try without the pages bit:

query: site.index(true).filterBy("template","in",["service","project"])

I’m sure I tried it without the pages, tried again: no joy, I only get pages from the projects. Hmm, when I think of it, and I should do that more often, it makes sense. I’m using the services as a data container only, so I didn’t add a template, added one and problem solved. Thanks for making me think :wink:

If you don’t need the template, then use intendedTemplate instead of template, that works without the template existing. Still, this pages bit is superfluous.

Ok, thanks will do.
Just one more thing how do I loop through the listed and drafts items in my template?
$articles = $page->articles()->toPages(); give me the listed items.

I think you probably need a custom field method for this.

Never mind, I’m forgetting about draft and use unlisted (my default template points to the error page).

Was wondering why you wanted to use drafts for public facing pages anyway…

Because they are not displayed as such. It’s just nice to combine them with other ‘real’ pages in the panel so we can drag and drop them in the order we like.