Query Plugin DataRank Math
Rank Math
Examples of queries to interact with data from the Rank Math plugin.
Fetching SEO metadata
We can use meta fields to query SEO metadata:
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")
}
}
Updating SEO metadata
We can use meta mutations to update SEO metadata:
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")
}
}
}
Prev
Next