Gönderiler
Bunlar, gönderi verilerini çekmek ve değiştirmek için queries örnekleridir.
Gönderileri çekme
Yazar ve etiketleriyle birlikte tek bir gönderi:
query {
post(by: { id: 1 }) {
title
content
url
date
author {
id
name
}
tags {
id
name
}
}
}Yorumlarıyla birlikte 5 gönderinin listesi:
query {
posts(pagination: { limit: 5 }) {
id
title
excerpt
url
dateStr(format: "d/m/Y")
comments(pagination: { limit: 5 }) {
id
date
content
}
}
}Önceden belirlenmiş gönderilerin listesi:
query {
posts(filter: { ids: [1499, 1657] }) {
id
title
excerpt
url
date
}
}Gönderileri filtreleme:
query {
posts(
filter: { search: "wordpress", dateQuery: { after: "2019-06-01" } },
sort: { order: ASC, by: TITLE }
) {
id
title
excerpt
url
status
}
}Gönderi sonuçlarını sayma:
query {
postCount(
filter: { search: "api" }
)
}Gönderileri sayfalama:
query {
posts(
pagination: {
limit: 5,
offset: 5
}
) {
id
title
}
}Etiketli gönderiler:
query {
posts(
filter: { tagSlugs: ["graphql", "wordpress", "plugin"] }
) {
id
title
}
}Kategorili gönderiler:
query {
posts(
filter: { categoryIDs: [50, 190] }
) {
id
title
}
}Meta değerlerini çekme:
query {
posts {
title
metaValue(
key: "_wp_page_template",
)
}
}Oturum açmış kullanıcının gönderilerini çekme
post, posts ve postCount alanları yalnızca "publish" durumundaki gönderileri getirir.
Oturum açmış kullanıcının gönderilerini herhangi bir durumla ("publish", "pending", "draft" veya "trash") çekmek için şu alanları kullanın:
myPostmyPostsmyPostCount
query {
myPosts(filter: { status: [draft, pending] }) {
id
title
status
}
}Gönderi oluşturma
Yalnızca oturum açmış kullanıcılar gönderi oluşturabilir.
mutation {
createPost(
input: {
title: "Hi there!"
contentAs: { html: "How do you like it?" }
status: draft
tags: ["demo", "plugin"]
}
) {
status
errors {
__typename
...on ErrorPayload {
message
}
...on GenericErrorPayload {
code
}
}
postID
post {
status
title
content
url
date
author {
id
name
}
tags {
id
name
}
}
}
}Gönderileri güncelleme
Yalnızca ilgili yetkilere sahip kullanıcılar gönderileri düzenleyebilir.
mutation {
updatePost(
input: {
id: 1,
title: "This is my new title",
}
) {
status
errors {
__typename
...on ErrorPayload {
message
}
...on GenericErrorPayload {
code
}
}
post {
id
title
}
}
}Bu query, gönderiyi güncellemek için iç içe mutation kullanır:
mutation {
post(by: { id: 1 }) {
originalTitle: title
update(input: {
title: "This is my new title",
contentAs: { html: "This rocks!" }
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
post {
newTitle: title
content
}
}
}
}