Truy vấn dữ liệu PluginWP Meta SEO
WP Meta SEO
Các ví dụ về queries để tương tác với dữ liệu từ plugin WP Meta SEO.
Lấy metadata SEO
Chúng ta có thể sử dụng trường meta để truy vấn metadata 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")
}
}Cập nhật metadata SEO
Chúng ta có thể sử dụng mutations meta để cập nhật metadata 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")
}
}
}Next