Truy vấn dữ liệu PluginSEO Simple Pack
SEO Simple Pack
Các ví dụ về queries để tương tác với dữ liệu từ plugin SEO Simple Pack.
Lấy metadata SEO
Chúng ta có thể sử dụng các trường meta để truy vấn metadata SEO:
query GetPost($postId: ID!) {
post(by: { id: $postId }) {
id
title
metaTitle: metaValue(key: "ssp_meta_title")
metaDesc: metaValue(key: "ssp_meta_description")
focusKeyword: metaValue(key: "ssp_meta_keyword")
canonical: metaValue(key: "ssp_meta_canonical")
socialImage: metaValue(key: "ssp_meta_image")
}
}Cập nhật metadata SEO
Chúng ta có thể sử dụng các mutation meta để cập nhật metadata SEO:
mutation UpdatePost($postId: ID!) {
updatePost(
input: {
id: $postId
meta: {
ssp_meta_title: ["New title"],
ssp_meta_description: ["New description"],
ssp_meta_keyword: ["New focus keyword"],
ssp_meta_canonical: ["https://example.com/canonical-url"],
ssp_meta_image: ["https://example.com/social-image.jpg"],
}
}
) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
post {
id
metaTitle: metaValue(key: "ssp_meta_title")
metaDesc: metaValue(key: "ssp_meta_description")
focusKeyword: metaValue(key: "ssp_meta_keyword")
canonical: metaValue(key: "ssp_meta_canonical")
socialImage: metaValue(key: "ssp_meta_image")
}
}
}