Payload CMS package - get single item

default discord avatar
Plain134last year
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 help straight from the Payload team with an Enterprise License.