WordPress-gegevens opvragenPages
Pages
Dit zijn voorbeelden van queries om paginagegevens op te halen.
Pagina's ophalen
Een enkele pagina:
query {
page(by: { id: 2 }) {
id
title
content
url
date
}
}Een lijst van pagina's:
query {
pages(pagination: { limit: 5 }) {
id
title
excerpt
url
dateStr(format: "d/m/Y")
}
}Pagina's op het hoogste niveau met hun subpagina's:
query {
pages(filter: { parentID: 0 }) {
...PageProps
children {
...PageProps
children(pagination: { limit: 3 }) {
...PageProps
}
}
}
}
fragment PageProps on Page {
id
title
date
urlPath
}Pagina's van de ingelogde gebruiker ophalen
De velden page, pages en pageCount halen alleen pagina's op met de status "publish".
Om pagina's van de ingelogde gebruiker op te halen met elke status ("publish", "pending", "draft" of "trash"), gebruik je deze velden:
myPagemyPagesmyPageCount
query {
myPages(filter: { status: [draft, pending] }) {
id
title
status
}
}Pagina's aanmaken
Alleen ingelogde gebruikers kunnen pagina's aanmaken.
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
}
}
}
}Pagina's bijwerken
Alleen gebruikers met de bijbehorende rechten kunnen pagina's bewerken.
mutation {
updatePage(
input: {
id: 2,
title: "This is my new title",
}
) {
status
errors {
__typename
...on ErrorPayload {
message
}
...on GenericErrorPayload {
code
}
}
page {
id
title
}
}
}Deze query gebruikt geneste mutaties om de pagina bij te werken:
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
}
}
}
}Prev
Next