Nav Menus
Examples
How to get any nav menu data PRO FEATURE
- Query
- Result
query {
some_menu: nav_menu(identifier: "ID", value: 1) {
name
items {
title
url
type
children {
title
url
type
}
}
}
}
{
"some_menu": {
"name": "custom-menu",
"items": [
0: {
"title": "About",
"url": "https://builderius.test?page_id=31",
"type": "post_type",
"children": []
},
1: {
"title": "Contacts",
"url": "https://builderius.test?page_id=32",
"type": "post_type",
"children": []
},
2: {
"title": "Uncategorized",
"url": "https://builderius.test?cat=1",
"type": "taxonomy",
"children": [
0: {
"title": "Hello World",
"url": "https://builderius.test?page_id=21",
"type": "post_type"
},
1: {
"title": "Sample Page",
"url": "https://builderius.test?page_id=23",
"type": "post_type"
}
]
}
]
}
}
info
identifier
argument can accept "ID" or "slug" or "name" or "[[global data variable]]" or "{{local data variable}}".
value
argument is required.
How to get all nav menus data PRO FEATURE
- Query
- Result
query {
nav_menus {
name
items {
title
url
type
children {
title
url
type
}
}
}
}
{
"nav_menus": [
0: {
"name": "custom-menu",
"items": [
0: {
"title": "About",
"url": "https://builderius.test?page_id=31",
"type": "post_type",
"children": []
},
1: {
"title": "Contacts",
"url": "https://builderius.test?page_id=32",
"type": "post_type",
"children": []
},
2: {
"title": "Uncategorized",
"url": "https://builderius.test?cat=1",
"type": "taxonomy",
"children": [
0: {
"title": "Hello World",
"url": "https://builderius.test?page_id=21",
"type": "post_type"
},
1: {
"title": "Sample Page",
"url": "https://builderius.test?page_id=23",
"type": "post_type"
}
]
}
]
}
]
}
How to get output of any php function with arguments based on every nav menu item in nav menu PRO FEATURE
If we need for example to get output of function get_post_meta
for every nav menu item in nav menu, we can do it in this way:
- Query
- Result
query {
nav_menu(identifier: "ID", value: 1) {
items {
id: ID
title
url
color: php_function_output (
function: "get_post_meta",
arguments: [
"{{id}}",
"color",
true
]
)
}
}
}
{
"nav_menu": {
"items": [
{
"id": 1,
"title": "About",
"url": "https://builderius.test?page_id=31",
"color": "blue"
},
{
"id": 2,
"title": "Contacts",
"url": "https://builderius.test?page_id=32",
"color": "yellow"
}
]
}
}
info
In this example for every post we used local data variable id
- it is ID
field of nav menu item but aliased like id
.
::::