WordPress verilerini sorgulaPages
Pages
Bunlar, sayfa verilerini çekmek için queries örnekleridir.
Sayfaları çekme
Tek bir sayfa:
query {
page(by: { id: 2 }) {
id
title
content
url
date
}
}Sayfa listesi:
query {
pages(pagination: { limit: 5 }) {
id
title
excerpt
url
dateStr(format: "d/m/Y")
}
}Alt sayfalarıyla birlikte üst düzey sayfalar:
query {
pages(filter: { parentID: 0 }) {
...PageProps
children {
...PageProps
children(pagination: { limit: 3 }) {
...PageProps
}
}
}
}
fragment PageProps on Page {
id
title
date
urlPath
}Oturum açmış kullanıcının sayfalarını çekme
page, pages ve pageCount alanları yalnızca "publish" durumundaki sayfaları getirir.
Oturum açmış kullanıcının sayfalarını, herhangi bir durumda ("publish", "pending", "draft" veya "trash") çekmek için şu alanları kullanın:
myPagemyPagesmyPageCount
query {
myPages(filter: { status: [draft, pending] }) {
id
title
status
}
}Sayfa oluşturma
Yalnızca oturum açmış kullanıcılar sayfa oluşturabilir.
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
}
}
}
}Sayfaları güncelleme
Yalnızca ilgili yetkililere sahip kullanıcılar sayfaları düzenleyebilir.
mutation {
updatePage(
input: {
id: 2,
title: "This is my new title",
}
) {
status
errors {
__typename
...on ErrorPayload {
message
}
...on GenericErrorPayload {
code
}
}
page {
id
title
}
}
}Bu query, sayfayı güncellemek için iç içe mutation'lar kullanır:
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