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.

How do you handle nested taxonomies?

default discord avatar
thgh.2 years ago
3

Wordpress has this pretty well covered.

  • discord user avatar
    jacobsfletch
    2 years ago

    Enable the nested docs plugin

    https://github.com/payloadcms/plugin-nested-docs

    on a

    categories

    collection then use a relationship field to reference the category



    Here's an example

    categories

    collection


    {
        slug: 'categories',
        name: 'Categories',
        fields: [
            {
                name: 'name',
                type: 'text',
            }
        ]
    }


    Then in your Payload config, call the plugin



    import nestedDocs from '@payloadcms/plugin-nested-docs'
    
    export default buildConfig({
      ...
      nestedDocs({
        collections: ['categories'],
      }),
    })


    Then in a

    posts

    collection, use a relationship field



    {
        slug: 'posts',
        name: 'Posts',
        fields: [
            {
                name: 'title',
                type: 'text',
            },
            {
                name: 'categories',
                type: 'relationship',
                hasMany: true,
                relationTo: 'categories',
            }
        ]
    }


    This would enable something like

    News > Politics > United States
  • default discord avatar
    thgh.2 years ago

    Oh lol, I thought docs stood for documentation, unfortunate naming 😛



    Thanks, will check it out!

  • discord user avatar
    jacobsfletch
    2 years ago

    Ahh makes sense. The original concept was actually “nested pages” but since this pattern applies to collections of any type “nested docs” made the most sense

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.