Requêter les données des plugins
Requêter les données des pluginsWP Meta SEO

WP Meta SEO

Exemples de requêtes pour interagir avec les données du plugin WP Meta SEO.

Récupérer les métadonnées SEO

Nous pouvons utiliser les valeurs méta pour interroger les métadonnées SEO :

query GetPost($postId: ID!) {
  post(by: { id: $postId }) {
    id
    title
 
    metaTitle: metaValue(key: "_metaseo_metatitle")
    metaDesc: metaValue(key: "_metaseo_metadesc")
    focusKeyword: metaValue(key: "_metaseo_metaspecific_keywords")
    socialFBTitle: metaValue(key: "_metaseo_metaopengraph-title")
    socialFBDesc: metaValue(key: "_metaseo_metaopengraph-desc")
    socialFBImage: metaValue(key: "_metaseo_metaopengraph-image")
    socialTwitterTitle: metaValue(key: "_metaseo_metatwitter-title")
    socialTwitterDesc: metaValue(key: "_metaseo_metatwitter-desc")
    socialTwitterImage: metaValue(key: "_metaseo_metatwitter-image")
  }
}

Mettre à jour les métadonnées SEO

Nous pouvons utiliser les mutations méta pour mettre à jour les métadonnées SEO :

mutation UpdatePost($postId: ID!) {
  updateCustomPostMetas(inputs: [
    { id: $postId, key: "_metaseo_metatitle", value: "New title" },
    { id: $postId, key: "_metaseo_metadesc", value: "New description" },
    { id: $postId, key: "_metaseo_metaspecific_keywords", value: "New focus keyword" },
    { id: $postId, key: "_metaseo_metaopengraph-title", value: "Social title" },
    { id: $postId, key: "_metaseo_metaopengraph-desc", value: "Social description" },
    { id: $postId, key: "_metaseo_metaopengraph-image", value: "https://example.com/social-image.jpg" },
    { id: $postId, key: "_metaseo_metatwitter-title", value: "Social title" },
    { id: $postId, key: "_metaseo_metatwitter-desc", value: "Social description" },
    { id: $postId, key: "_metaseo_metatwitter-image", value: "https://example.com/social-image.jpg" },
  ]) {
    status
    errors {
      __typename
      ...on ErrorPayload {
        message
      }
    }
    customPost {
      __typename
      id
      metaTitle: metaValue(key: "_metaseo_metatitle")
      metaDesc: metaValue(key: "_metaseo_metadesc")
      focusKeyword: metaValue(key: "_metaseo_metaspecific_keywords")
      socialFBTitle: metaValue(key: "_metaseo_metaopengraph-title")
      socialFBDesc: metaValue(key: "_metaseo_metaopengraph-desc")
      socialFBImage: metaValue(key: "_metaseo_metaopengraph-image")
      socialTwitterTitle: metaValue(key: "_metaseo_metatwitter-title")
      socialTwitterDesc: metaValue(key: "_metaseo_metatwitter-desc")
      socialTwitterImage: metaValue(key: "_metaseo_metatwitter-image")
    }
  }
}