Payload CMS package - get single item

default discord avatar
Plain134
last month
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
  }
Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!

Star

Connect with the Payload Community on Discord

Discord

online

Can't find what you're looking for?

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