Thư viện QueriesThay thế slug bài viết cũ bằng slug mới trong tất cả bài viết
Thay thế slug bài viết cũ bằng slug mới trong tất cả bài viết
Sau khi thay đổi slug của một bài viết, hãy thực thi query này để chuyển đổi toàn bộ nội dung trỏ đến URL mới.
Query này yêu cầu endpoint phải bật Nested Mutations.
query ExportData(
$oldPostSlug: String!
$newPostSlug: String!
) {
siteURL: optionValue(name: "siteurl")
oldPostURL: _strAppend(
after: $__siteURL,
append: $oldPostSlug
) @export(as: "oldPostURL")
newPostURL: _strAppend(
after: $__siteURL,
append: $newPostSlug
) @export(as: "newPostURL")
}
mutation ReplaceOldWithNewSlugInPosts
@depends(on: "ExportData")
{
posts(
filter: {
search: $oldPostURL
},
pagination: {
limit: -1
}
) {
id
rawContent
adaptedRawContent: _strReplace(
search: $oldPostURL
replaceWith: $newPostURL
in: $__rawContent
)
update(input: {
contentAs: { html: $__adaptedRawContent }
}) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
post {
id
rawContent
}
}
}
}