Запрос данных WordPressКатегории записей
Категории записей
Это примеры queries для получения данных категорий записей.
Получение категорий
Список категорий записей с сортировкой по имени и отображением количества записей:
query {
postCategories(
sort: { order: ASC, by: NAME }
pagination: { limit: 50 }
) {
id
name
url
postCount
}
}Все категории в записи:
query {
post(by: { id: 1 }) {
categories {
id
name
url
}
}
}Названия категорий в записях:
query {
posts {
id
title
categoryNames
}
}Список заранее определённых категорий:
query {
postCategories(filter: { ids: [2, 5] }) {
id
name
url
}
}Фильтрация категорий по имени:
query {
postCategories(filter: { search: "rr" }) {
id
name
url
}
}Подсчёт результатов категорий:
query {
postCategoryCount(filter: { search: "rr" })
}Разбивка категорий на страницы:
query {
postCategories(
pagination: {
limit: 3,
offset: 3
}
) {
id
name
url
}
}Только категории верхнего уровня и 2-й уровень дочерних:
{
postCategories(pagination: { limit: 50 }, filter: { parentID: 0 }) {
...CatProps
children {
...CatProps
children {
...CatProps
}
}
}
}
fragment CatProps on PostCategory {
id
name
parent {
id
name
}
childNames
childCount
}Получение мета-значений:
query {
postCategories(
pagination: { limit: 5 }
) {
id
name
metaValue(
key: "someKey"
)
}
}Назначение категорий записи
Мутация:
mutation {
setCategoriesOnPost(
input: {
id: 1499,
categoryIDs: [2, 5]
}
) {
status
errors {
__typename
... on ErrorPayload {
message
}
}
postID
post {
categories {
id
}
categoryNames
}
}
}Вложенная мутация:
mutation {
post(by: { id: 1499 }) {
setCategories(
input: {
categoryIDs: [2, 5]
}
) {
status
errors {
__typename
... on ErrorPayload {
message
}
}
postID
post {
categories {
id
}
categoryNames
}
}
}
}Создание, обновление и удаление категории записи
Этот запрос создаёт, обновляет и удаляет термины категорий записей:
mutation CreateUpdateDeletePostCategories {
createPostCategory(input: {
name: "Some name"
slug: "Some slug"
description: "Some description"
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
category {
...PostCategoryData
}
}
updatePostCategory(input: {
id: 1
name: "Some updated name"
slug: "Some updated slug"
description: "Some updated description"
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
category {
...PostCategoryData
}
}
deletePostCategory(input: {
id: 1
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
}
}
fragment PostCategoryData on PostCategory {
id
name
slug
description
parent {
id
}
}