Post Categories
These are examples of queries to fetch post category data.
Fetching categories permalink
List of post categories, ordering them by name, and showing their post count:
query {
postCategories(
sort: { order: ASC, by: NAME }
pagination: { limit: 50 }
) {
id
name
url
postCount
}
}
All categories in a post:
query {
post(by: { id: 1 }) {
categories {
id
name
url
}
}
}
Category names in posts:
query {
posts {
id
title
categoryNames
}
}
A list of predefined categories:
query {
postCategories(filter: { ids: [2, 5] }) {
id
name
url
}
}
Filtering categories by name:
query {
postCategories(filter: { search: "rr" }) {
id
name
url
}
}
Counting category results:
query {
postCategoryCount(filter: { search: "rr" })
}
Paginating categories:
query {
postCategories(
pagination: {
limit: 3,
offset: 3
}
) {
id
name
url
}
}
Only top-level categories, and 2nd level of children:
{
postCategories(pagination: { limit: 50 }, filter: { parentID: 0 }) {
...CatProps
children {
...CatProps
children {
...CatProps
}
}
}
}
fragment CatProps on PostCategory {
id
name
parent {
id
name
}
childNames
childCount
}
Fetching meta values:
query {
postCategories(
pagination: { limit: 5 }
) {
id
name
metaValue(
key: "someKey"
)
}
}
Setting categories on a post permalink
Mutation:
mutation {
setCategoriesOnPost(
input: {
id: 1499,
categoryIDs: [2, 5]
}
) {
status
errors {
__typename
... on ErrorPayload {
message
}
}
postID
post {
categories {
id
}
categoryNames
}
}
}
Nested mutation:
mutation {
post(by: { id: 1499 }) {
setCategories(
input: {
categoryIDs: [2, 5]
}
) {
status
errors {
__typename
... on ErrorPayload {
message
}
}
postID
post {
categories {
id
}
categoryNames
}
}
}
}