Nest entries under parent entries
Use a parent model when one entry belongs inside another, such as chapters inside a book. Each chapter then has one parent book, and the API can list the chapters of that book.
Before you start
- You need the administrator role.
- The parent model must be a node model. The Can be placed under list shows node models only.
- The child model must already exist and must be a node model. Only node models have the Advanced tab.
Set the parent models
- In the sidebar, select Models.
- Open the model for the child entries, for example a model named chapter.
- Select Advanced.
- In Can be placed under, select each model that can be the parent. For example, select the book model.
- In Moving, select one option. The Moving field appears after you select a parent model. Warning: With Entries stay under their parent (faster for huge trees), saving an entry with a different parent fails. Select Entries can move to another parent if editors must move entries.
- Default: entries stay under their parent.
- Entries can move to another parent: an entry can be moved to a different parent.
- Entries stay under their parent (faster for huge trees): an entry cannot be moved to a different parent.
- Optional: In Parent, select Required to refuse entries that have no parent. The default is Optional.
- Select Save changes.
Result: The entry editor shows a Parent property for entries of this model. Choose the parent entry there.
List the children of a parent
Send a GET request with the parent's id in the parent parameter. Replace boo_… with the id of your parent entry.
curl "https://example.com/wp-json/morphic/v1/items/chapter?parent=boo_…"
Result: The response lists the chapter entries under that parent.