Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

How would I filter out drafts in a localapi query?

default discord avatar
banks0last year
4

Title basically 🙂

  • discord user avatar
    tylandavis
    last year

    Here's an example for a

    posts

    collection to get only published documents:



    const getPosts = async () => {
      const posts = await payload.find({
        collection: "posts",
        where: {
          _status: {
            equals: "published",
          },
        },
      });
  • default discord avatar
    banks0last year

    thanks



    -> only return published and in with specific where

  • discord user avatar
    tylandavis
    last year

    hey @banks , sorry for the late reply on this, you can combine multiple query conditions using

    and

    like so:



    where: {
      and: [
        _status: {
          equals: "published",
        },
        "group.slug": {
          equals: slug,
        },
      ],
    }


    You can also use

    or

    as well, which works the same way. That would return documents that satisfy

    either

    condition, wheras

    and

    must satisfy both/all conditions.

    https://payloadcms.com/docs/queries/overview#and-or-logic
  • default discord avatar
    banks0last year

    thanks, I appreciate it

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.