like the title says, how can i use the relationship field to only select a collection item that has a status of published? i dont want users of the cms to be able to pick drafts.
Hey @olarssony , to do this, just pass a query constraint to the
filterOptions
property on your relationship field config:
{
name: "relatedPosts",
type: "relationship",
relationTo: "posts",
filterOptions: () => {
return {
_status: {
equals: 'published'
}
}
},
},
You can find more about the
filterOptions
and creating queries here:
cheers! thanks man
no problem! glad I could help.
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.