My posts collections includes tags as follows
{
name: 'tags',
type: 'relationship',
relationTo: 'tags',
hasMany: true,
},
I want to be able to filter the response by tag name. I also want to place a limit of 6 so I don't break my pagination, etc.
Given a tag of "Guides", shouldn't I be able to filter my posts using
https://domain.com/api/posts?where[tags][equals]=Guides&limit=6&page=1
The above url params don't work. I've attached a screenshot of the api response.
I'm using this url based on my interpretation of the following documentation -
https://payloadcms.com/docs/queries/overview#rest-queriesWhat am I doing wrong?
Hey, I see that you are using
hasMany: true
, so you should try with something like
?where[tags.name][equals]=tagname
where name is a property from Tags collection
You can find more details in this section:
https://payloadcms.com/docs/fields/relationship#how-the-data-is-saved, and more specifically under "Has Many - Polymorphic"
That worked perfectly. Thanks
Star
Discord
online
Get help straight from the Payload team with an Enterprise License.