How would I filter out drafts in a localapi query?

default discord avatar
banks012 months ago
4

Title basically 🙂

  • discord user avatar
    tylandavis
    12 months ago

    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
    banks012 months ago

    thanks



    -> only return published and in with specific where

  • discord user avatar
    tylandavis
    12 months ago

    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
    banks012 months ago

    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.