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.

Payload CMS package - get single item

default discord avatar
plainnn2 years ago
2

Is it possible to get a single document from a collection using the slug/id?



I'm using this to get all of the blog-posts, but on the singular blog post page would ideally just get the required one



  const getPosts = async () => {
    const posts = await payload.find({
      collection: 'client-posts',
    })
    return posts
  }


I've tried the following, but it didn't work (

context.params.slug[0]

is definitely valid)


  const getPosts = async () => {
    const posts = await payload.find({
      collection: 'client-projects',
      where: {
        slug: {
          equals: context.params.slug[0],
        },
      },
    })
    return posts
  }
Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.