Skip to content

Commit 9d8a99d

Browse files
Update docs on querying entry statuses (#1340)
Co-authored-by: Jason Varga <[email protected]>
1 parent 4592d54 commit 9d8a99d

File tree

2 files changed

+49
-8
lines changed

2 files changed

+49
-8
lines changed

content/collections/docs/4-to-5.md

+47
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,53 @@ If you use this `{{ glide filename="" }}` parameter, you'll need to remove remov
377377

378378
If you are hot-linking to any images rendered with manually set filenames in this way, you'll also need to correct those links.
379379

380+
### Entries may now only be queried by a single status
381+
**Affects any apps or addons filtering entries by `status`.**
382+
383+
Previously, when querying entries, you could use *any* condition to filter entries.
384+
385+
However, in v5, as part of improvements to how statuses work behind the schenes, statuses can now only be filtered using the `is` / `equals` conditions, and the `whereStatus` query method. Some examples:
386+
387+
Collection tag:
388+
```antlers
389+
{{ collection:blog status:in="published" }} {{# [tl! --] #}}
390+
{{ collection:blog status:is="published" }} {{# [tl! ++] #}}
391+
```
392+
393+
PHP:
394+
```php
395+
Entry::query()
396+
->where('collection', 'blog')
397+
->where('status', 'published') // [tl! --]
398+
->whereStatus('published') // [tl! ++]
399+
->get();
400+
```
401+
402+
REST API:
403+
```php
404+
/api/collections/blog/entries?filter[status:in]=published // [tl! --]
405+
/api/collections/blog/entries?filter[status]=published // [tl! ++]
406+
```
407+
408+
GraphQL API:
409+
```graphql
410+
{
411+
entries(
412+
collection: "blog"
413+
filter: {
414+
status: { in: "published" } #[tl! --]
415+
status: "published" #[tl! ++]
416+
}
417+
) {
418+
data {
419+
title
420+
}
421+
}
422+
}
423+
```
424+
425+
Let us know if you need to query by multiple statuses by opening a [GitHub issue](https://github.com/statamic/cms).
426+
380427
## Zero impact changes
381428

382429
These are items that you can completely ignore. They are suggestions on how to improve your code using newly added features.

content/collections/tags/collection.md

+2-8
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,8 @@ There are several different ways to use this filtering parameter. They are expla
214214
By default, only `published` entries are included. Entries can be queried against `draft`, `scheduled`, or `expired` status with [conditions](#conditions) on `status` like this:
215215

216216
```
217-
// Include draft entries
218-
{{ collection:blog status:in="published|draft" }}
219-
220-
// Only include expired entries
221-
{{ collection:blog status:is="expired" }}
222-
223-
// Exclude published entries
224-
{{ collection:blog status:not_in="published" }}
217+
// Only include published entries
218+
{{ collection:blog status:is="published" }}
225219
```
226220

227221
:::tip

0 commit comments

Comments
 (0)