Query-bibliotheek
Query-bibliotheekVervang een oude post-slug door een nieuwe post-slug in alle posts

Vervang een oude post-slug door een nieuwe post-slug in alle posts

Na het wijzigen van de slug van een post, voer je deze query uit om alle content te converteren zodat die naar de nieuwe URL verwijst.

Deze query vereist dat het endpoint Geneste mutaties heeft ingeschakeld.

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
      }
    }
  }
}