WordPress 데이터 쿼리메뉴
메뉴
다음은 메뉴 데이터를 가져오는 쿼리 예시입니다.
메뉴 가져오기
특정 메뉴와 해당 항목의 원시 데이터를 가져옵니다:
{
menu(by: { id: 176 }) {
itemDataEntries
}
}include 또는 exclude를 사용하여 메뉴 항목 속성을 필터링합니다:
{
menu(by: { id: 176 }) {
itemDataEntries(propertiesBy: { exclude: ["localURLPath", "rawLabel"] })
}
}모든 메뉴를 가져오고, 쿼리를 중첩하여 항목의 속성을 선택합니다:
{
menus {
id
name
slug
count
locations
items {
...MenuItemData
children {
...MenuItemData
children {
...MenuItemData
}
}
}
}
}
fragment MenuItemData on MenuItem {
id
itemType
objectType
objectID
parentID
localURLPath
label
rawLabel
titleAttribute
url
cssClasses
target
description
linkRelationship
}메뉴 필터링 및 페이지네이션:
{
menus(pagination: { limit: 1, offset: 1}, filter: { search: "all" }) {
id
name
slug
}
menuCount(filter: { search: "all" })
}메뉴 생성
관리자 사용자(또는 edit_theme_options 권한을 가진 사용자)만 메뉴를 생성하거나 업데이트할 수 있습니다.
mutation CreateMenu {
createMenu(input: {
name: "Header menu"
locations: ["header"]
itemsBy: { json: [
{
label: "Custom parent (nested)",
itemType: custom,
url: "https://www.example.com/parent",
titleAttribute: "Parent title attribute",
description: "Parent menu item description",
cssClasses: ["menu-item", "menu-item-parent"],
target: "_blank",
linkRelationship: "nofollow",
children: [
{
label: "Custom child",
itemType: custom,
url: "https://www.example.com/parent/child",
description: "Child menu item description",
cssClasses: ["menu-item", "menu-item-child"],
target: "_self",
linkRelationship: "follow"
},
{
label: "Page child",
itemType: post_type,
objectType: "page",
objectID: 2,
titleAttribute: "Go to sample page",
description: "Page child description",
cssClasses: ["menu-item", "menu-item-page"],
target: "_blank",
linkRelationship: "nofollow"
},
{
label: "Category child",
itemType: taxonomy,
objectType: "category",
objectID: 3
}
]
},
{
label: "Root page item",
itemType: post_type,
objectType: "page",
objectID: 2
},
{
label: "Root category item",
itemType: taxonomy,
objectType: "category",
objectID: 5
},
{
label: "Custom root item",
itemType: custom,
url: "https://www.example.com/2",
description: "Custom root item description",
cssClasses: ["menu-item", "menu-item-root"],
target: "_self",
linkRelationship: "follow",
children: [
{
label: "Custom grandchild",
itemType: custom,
url: "https://www.example.com/2/grandchild",
description: "Custom grandchild description",
cssClasses: ["menu-item", "menu-item-grandchild"],
target: "_blank",
linkRelationship: "nofollow"
}
]
}
] }
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
menu {
id
name
slug
count
locations
itemDataEntries
items {
...MenuItemData
children {
...MenuItemData
children {
...MenuItemData
children {
...MenuItemData
}
}
}
}
}
}
}
fragment MenuItemData on MenuItem {
id
itemType
objectType
objectID
parentID
localURLPath
label
rawLabel
titleAttribute
url
cssClasses
target
description
linkRelationship
}메뉴 업데이트
메뉴 위치를 업데이트합니다:
mutation UpdateMenu {
updateMenu(input: {
id: 176
locations: ["footer", "footer-mobile"]
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
menu {
id
locations
}
}
}이 쿼리는 중첩된 뮤테이션을 사용하여 메뉴 이름을 업데이트합니다:
mutation {
menu(by: { id: 176 }) {
originalName: name
update(input: {
name: "Mobile header menu"
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
menu {
newName: name
}
}
}
}