Zapytania o dane WordPress
Zapytania o dane WordPressTagi posta

Tagi posta

To są przykłady queries do pobierania danych tagów posta.

Pobieranie tagów

Lista tagów posta, posortowanych według nazwy, z wyświetleniem liczby postów:

query {
  postTags(
    sort: { order: ASC, by: NAME }
    pagination: { limit: 50 }
  ) {
    id
    name
    url
    postCount
  }
}

Wszystkie tagi w poście:

query {
  post(by: { id: 1 }) {
    tags {
      id
      name
      url
    }
  }
}

Nazwy tagów w postach:

query {
  posts {
    id
    title
    tagNames
  }
}

Lista predefiniowanych tagów:

query {
  postTags(filter: { ids: [66, 70, 191] }) {
    id
    name
    url
  }
}

Filtrowanie tagów według nazwy:

query {
  postTags(filter: { search: "oo" }) {
    id
    name
    url
  }
}

Liczenie wyników tagów:

query {
  postTagCount(filter: { search: "oo" })
}

Paginowanie tagów:

query {
  postTags(
    pagination: {
      limit: 5,
      offset: 5
    }
  ) {
    id
    name
    url
  }
}

Pobieranie wartości meta:

query {
  postTags(
    pagination: { limit: 5 }
  ) {
    id
    name
    metaValue(
      key: "someKey"
    )
  }
}

Ustawianie tagów na poście

Mutation:

mutation {
  setTagsOnPost(
    input: {
      id: 1499, 
      tags: ["api", "development"]
    }
  ) {
    status
    errors {
      __typename
      ... on ErrorPayload {
        message
      }
    }
    postID
    post {
      tags {
        id
      }
      tagNames
    }
  }
}

Zagnieżdżona mutation:

mutation {
  post(by: { id: 1499 }) {
    setTags(
      input: {
        tags: ["api", "development"]
      }
    ) {
      status
      errors {
        __typename
        ... on ErrorPayload {
          message
        }
      }
      postID
      post {
        tags {
          id
        }
        tagNames
      }
    }
  }
}

Tworzenie, aktualizowanie i usuwanie tagu posta

To query tworzy, aktualizuje i usuwa terminy tagów posta:

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
}