WordPress-Daten abfragen
WordPress-Daten abfragenPost-Tags

Post-Tags

Dies sind Beispiele für queries zum Abrufen von Post-Tag-Daten.

Tags abrufen

Liste der Post-Tags, nach Name sortiert und mit der Anzahl der Posts:

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

Alle Tags in einem Post:

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

Tag-Namen in Posts:

query {
  posts {
    id
    title
    tagNames
  }
}

Eine Liste vordefinierter Tags:

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

Tags nach Name filtern:

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

Tag-Ergebnisse zählen:

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

Tags paginieren:

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

Meta-Werte abrufen:

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

Tags an einem Post setzen

Mutation:

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

Verschachtelte Mutation:

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

Einen Post-Tag erstellen, aktualisieren und löschen

Diese query erstellt, aktualisiert und löscht Post-Tag-Terme:

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
}