Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Get full collection inside another query

default discord avatar
reepicheep052 years ago
4

Is there a way to create a field that returns a full collection? I have a

Page

collection and a

Blog

collection in the CMS. Each page entry has a dropdown where I can choose a

Blog

post category and display the posts. I am trying to get the full

Blog

feed in the return from the

Page

query.



I know I can just query the feed in the component, but I was wondering if there is a way to do this in the first

Page

query.



Thanks!

  • default discord avatar
    paulpopus2 years ago

    You can use a relationship field, choose a blog post. Then when you query your page just make sure you set your

    depth

    to a higher number, maybe 2 or 3 but it will depend on your data structure on blogs

  • default discord avatar
    reepicheep052 years ago

    Hey thanks paul, I am acutally trying to get all the blog post feed. I was thinking that I could use the select field to choose the feed (eg. blog posts, case studies etc)

  • default discord avatar
    paulpopus2 years ago

    Ohhh I see, via the REST API, this is two separate queries right now



    If you want to make things easier for yourself you could set up a custom REST endpoint



    https://payloadcms.com/docs/rest-api/overview#custom-endpoints

    So you could set up a custom one to get a feed, then inside your handler you would do the logic of fetching the target Page's category and then do a find for blog feed

  • default discord avatar
    reepicheep052 years ago

    Got it. Thanks Paul!

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.