#Payload CMS package - get single item

2 messages · Page 1 of 1 (latest)

fading moth
#

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
  }
serene flume