Skip to content

Commit

Permalink
Update docs on querying entry statuses (#1340)
Browse files Browse the repository at this point in the history
Co-authored-by: Jason Varga <[email protected]>
  • Loading branch information
duncanmcclean and jasonvarga authored May 22, 2024
1 parent 4592d54 commit 9d8a99d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 8 deletions.
47 changes: 47 additions & 0 deletions content/collections/docs/4-to-5.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,53 @@ If you use this `{{ glide filename="" }}` parameter, you'll need to remove remov

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

### Entries may now only be queried by a single status
**Affects any apps or addons filtering entries by `status`.**

Previously, when querying entries, you could use *any* condition to filter entries.

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:

Collection tag:
```antlers
{{ collection:blog status:in="published" }} {{# [tl! --] #}}
{{ collection:blog status:is="published" }} {{# [tl! ++] #}}
```

PHP:
```php
Entry::query()
->where('collection', 'blog')
->where('status', 'published') // [tl! --]
->whereStatus('published') // [tl! ++]
->get();
```

REST API:
```php
/api/collections/blog/entries?filter[status:in]=published // [tl! --]
/api/collections/blog/entries?filter[status]=published // [tl! ++]
```

GraphQL API:
```graphql
{
entries(
collection: "blog"
filter: {
status: { in: "published" } #[tl! --]
status: "published" #[tl! ++]
}
) {
data {
title
}
}
}
```

Let us know if you need to query by multiple statuses by opening a [GitHub issue](https://github.com/statamic/cms).

## Zero impact changes

These are items that you can completely ignore. They are suggestions on how to improve your code using newly added features.
Expand Down
10 changes: 2 additions & 8 deletions content/collections/tags/collection.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,8 @@ There are several different ways to use this filtering parameter. They are expla
By default, only `published` entries are included. Entries can be queried against `draft`, `scheduled`, or `expired` status with [conditions](#conditions) on `status` like this:

```
// Include draft entries
{{ collection:blog status:in="published|draft" }}
// Only include expired entries
{{ collection:blog status:is="expired" }}
// Exclude published entries
{{ collection:blog status:not_in="published" }}
// Only include published entries
{{ collection:blog status:is="published" }}
```

:::tip
Expand Down

0 comments on commit 9d8a99d

Please sign in to comment.