0

I am wondering if it is possible to filter content in Sanity Studio according to set criteria. For example, return all published posts or all posts within a particular category, etc.

Here is a short video showing what I mean: https://www.loom.com/share/5af3a9dd79f045458de00e8f5365cf00

Is this possible? If so, is there any documentation on how to do it?

Thanks.

Moshe
  • 6,011
  • 16
  • 60
  • 112

1 Answers1

0

The easiest way I've found to make all kinds of filters is using the Structure Builder. With it you add as many sections you like, name them, and give it your own filter in the form of groq and params.

Se documentation: https://www.sanity.io/docs/structure-builder-introduction

As an example I've added a S.listItem to the deskStructure.js file that gets all articles that are missing the module field.

export default async () =>
    S.list()
        .title('Content')
        .items([
            // ...
            S.listItem()  //  <-- New root item for my filters
                .title('My article filters')
                .icon(FaRegCopyright)
                .child(
                    S.list()  //  <-- List of filters
                        .title('My article filters')
                        .items([
                            S.listItem()  //  <-- Item with filter description
                                .title('Articles without module')
                                .icon(FaCogs)
                                .child(
                                    S.documentList()  //  <-- Filtered list of articles
                                        .title('Articles without module')
                                        .menuItems(S.documentTypeList(menuType).getMenuItems())
                                        .filter('_type == $type && !defined(module)')
                                        .params({ type: 'article' })
                                ),
                            S.listItem(), // more filters
                            S.listItem(), // more filters
                        ])
                ),
            // ...

It doesn't make different filters on one list of elements. It's more making different lists that are all ready filtered as you need. And you can give it what ever icon and text you want. Potato/potàto ,'-)

In the sorting list I don't think you can do much other than adding more sorting. And It doesn't work when the list of elements get larger anyways so I wouldn't bother. But it's in the Sort Order section: https://www.sanity.io/docs/sort-orders

cfm
  • 156
  • 1
  • 2
  • 12