Libreria di queries
Libreria di queriesSostituire un vecchio slug di post con un nuovo slug in tutti i post

Sostituire un vecchio slug di post con un nuovo slug in tutti i post

Dopo aver modificato lo slug di un post, esegui questa query per convertire tutto il contenuto affinché punti al nuovo URL.

Questa query richiede che l'endpoint abbia le Mutazioni annidate abilitate.

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