Query WordPress dataPost Tags
Post Tags
These are examples of queries to fetch post tag data.
Fetching tags
List of post tags, ordering them by name, and showing their post count:
query {
postTags(
sort: { order: ASC, by: NAME }
pagination: { limit: 50 }
) {
id
name
url
postCount
}
}
All tags in a post:
query {
post(by: { id: 1 }) {
tags {
id
name
url
}
}
}
Tag names in posts:
query {
posts {
id
title
tagNames
}
}
A list of predefined tags:
query {
postTags(filter: { ids: [66, 70, 191] }) {
id
name
url
}
}
Filtering tags by name:
query {
postTags(filter: { search: "oo" }) {
id
name
url
}
}
Counting tag results:
query {
postTagCount(filter: { search: "oo" })
}
Paginating tags:
query {
postTags(
pagination: {
limit: 5,
offset: 5
}
) {
id
name
url
}
}
Fetching meta values:
query {
postTags(
pagination: { limit: 5 }
) {
id
name
metaValue(
key: "someKey"
)
}
}
Setting tags on a post
Mutation:
mutation {
setTagsOnPost(
input: {
id: 1499,
tags: ["api", "development"]
}
) {
status
errors {
__typename
... on ErrorPayload {
message
}
}
postID
post {
tags {
id
}
tagNames
}
}
}
Nested mutation:
mutation {
post(by: { id: 1499 }) {
setTags(
input: {
tags: ["api", "development"]
}
) {
status
errors {
__typename
... on ErrorPayload {
message
}
}
postID
post {
tags {
id
}
tagNames
}
}
}
}
Creating, updating and deleting a post tag
This query creates, updates and deletes post tag terms:
mutation CreateUpdateDeletePostTags {
createPostTag(input: {
name: "Some name"
slug: "Some slug"
description: "Some description"
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
category {
...PostTagData
}
}
updatePostTag(input: {
id: 1
name: "Some updated name"
slug: "Some updated slug"
description: "Some updated description"
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
category {
...PostTagData
}
}
deletePostTag(input: {
id: 1
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
}
}
fragment PostTagData on PostTag {
id
name
slug
description
}
Prev
Next