How do I get all of an entry's children using the Element API?
I want to return something like:
data: [
title: 'Root Entry'
uri: 'root-entry'
children: [
{
title: 'Level 2 Entry'
uri: 'level-2-entry-1'
children: [
{
title: 'Level 3 Entry'
uri: 'level-3-entry'
children: [...]
},
]
},
{
title: 'Level 2 Entry'
uri: 'level-2-entry-2'
children: [...]
},
{
title: 'Level 2 Entry'
uri: 'level-2-entry-3'
children: [...]
},
]
]
I would want to get all entries up to the depth level of 4. Some entries wont have children past level 3 and some wont have any past level 2. I have tried doing a for loop traversal but cannot figure out why $entry->children
returns everything but children entries.