Interrogare i dati di WordPress
Interrogare i dati di WordPressTag del post

Tag del post

Questi sono esempi di queries per recuperare i dati dei tag del post.

Recupero dei tag

Elenco dei tag del post, ordinati per nome e con il conteggio dei post:

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

Tutti i tag in un post:

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

Nomi dei tag nei post:

query {
  posts {
    id
    title
    tagNames
  }
}

Un elenco di tag predefiniti:

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

Filtrare i tag per nome:

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

Conteggio dei risultati dei tag:

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

Paginazione dei tag:

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

Recupero dei valori meta:

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

Impostare tag su un post

Mutation:

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

Mutation annidata:

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

Creare, aggiornare ed eliminare un tag del post

Questa query crea, aggiorna ed elimina termini di tag del post:

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
}