Truy vấn dữ liệu Plugin
Truy vấn dữ liệu PluginRank Math

Rank Math

Các ví dụ về queries để tương tác với dữ liệu từ plugin Rank Math.

Lấy siêu dữ liệu SEO

Chúng ta có thể sử dụng trường meta để truy vấn siêu dữ liệu SEO:

query GetPost($postId: ID!) {
  post(by: { id: $postId }) {
    id
    title
 
    metaDesc: metaValue(key: "rank_math_description")
    focusKeyword: metaValue(key: "rank_math_focus_keyword")
    canonical: metaValue(key: "rank_math_canonical_url")
    socialTitle: metaValue(key: "rank_math_facebook_title")
    socialDesc: metaValue(key: "rank_math_facebook_description")
    socialImage: metaValue(key: "rank_math_facebook_image")
    twitterTitle: metaValue(key: "rank_math_twitter_title")
    twitterDesc: metaValue(key: "rank_math_twitter_description")
    twitterImage: metaValue(key: "rank_math_twitter_image")
  }
}

Cập nhật siêu dữ liệu SEO

Chúng ta có thể sử dụng đột biến meta để cập nhật siêu dữ liệu SEO:

mutation UpdatePost($postId: ID!) {
  updatePost(
    input: {
      id: $postId
      meta: {
        rank_math_description: ["New description"],
        rank_math_focus_keyword: ["New focus keyword"],
        rank_math_canonical_url: ["https://example.com/canonical-url"],
        rank_math_facebook_title: ["Social title"],
        rank_math_facebook_description: ["Social description"],
        rank_math_facebook_image: ["https://example.com/social-image.jpg"],
        rank_math_twitter_title: ["Twitter title"],
        rank_math_twitter_description: ["Twitter description"],
        rank_math_twitter_image: ["https://example.com/twitter-image.jpg"],
      }
    }
  ) {
    status
    errors {
      __typename
      ...on ErrorPayload {
        message
      }
    }
    post {
      id
      metaDesc: metaValue(key: "rank_math_description")
      focusKeyword: metaValue(key: "rank_math_focus_keyword")
      canonical: metaValue(key: "rank_math_canonical_url")
      socialTitle: metaValue(key: "rank_math_facebook_title")
      socialDesc: metaValue(key: "rank_math_facebook_description")
      socialImage: metaValue(key: "rank_math_facebook_image")
      twitterTitle: metaValue(key: "rank_math_twitter_title")
      twitterDesc: metaValue(key: "rank_math_twitter_description")
      twitterImage: metaValue(key: "rank_math_twitter_image")
    }
  }
}