WordPress 데이터 쿼리페이지
페이지
다음은 페이지 데이터를 가져오는 쿼리 예시입니다.
페이지 가져오기
단일 페이지:
query {
page(by: { id: 2 }) {
id
title
content
url
date
}
}페이지 목록:
query {
pages(pagination: { limit: 5 }) {
id
title
excerpt
url
dateStr(format: "d/m/Y")
}
}최상위 페이지와 하위 페이지:
query {
pages(filter: { parentID: 0 }) {
...PageProps
children {
...PageProps
children(pagination: { limit: 3 }) {
...PageProps
}
}
}
}
fragment PageProps on Page {
id
title
date
urlPath
}로그인한 사용자의 페이지 가져오기
page, pages, pageCount 필드는 상태가 "publish"인 페이지만 가져옵니다.
로그인한 사용자의 페이지를 임의의 상태("publish", "pending", "draft", "trash")로 가져오려면 다음 필드를 사용하세요:
myPagemyPagesmyPageCount
query {
myPages(filter: { status: [draft, pending] }) {
id
title
status
}
}페이지 생성
페이지는 로그인한 사용자만 생성할 수 있습니다.
mutation {
createPage(
input: {
title: "Hi there!"
contentAs: { html: "How do you like it?" }
status: draft
}
) {
status
errors {
__typename
...on ErrorPayload {
message
}
...on GenericErrorPayload {
code
}
}
pageID
page {
status
title
content
url
date
author {
id
name
}
}
}
}페이지 업데이트
페이지를 편집할 수 있는 것은 해당 권한을 가진 사용자뿐입니다.
mutation {
updatePage(
input: {
id: 2,
title: "This is my new title",
}
) {
status
errors {
__typename
...on ErrorPayload {
message
}
...on GenericErrorPayload {
code
}
}
page {
id
title
}
}
}이 쿼리는 중첩된 mutation을 사용하여 페이지를 업데이트합니다:
mutation {
page(by: { id: 2 }) {
originalTitle: title
update(input: {
title: "This is my new title",
contentAs: { html: "This rocks!" }
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
page {
newTitle: title
content
}
}
}
}