Programmatic Resetting of Article Slugs Causes Links to Fail

When our site was migrated, the tech at the host company uploaded our JSON file three times. This created triplicate articles on our website. They were kind enough to remove the duplicated articles, however, they removed the original article and the initial duplicate article, leaving the second duplicate article.

The second duplicate article slugs were all appended with “-3” to differentiate them from the original articles when they were imported into the Ghost installation.

I can run a query to truncate the appended “-3.” That part is simple enough. However, if I do so, the links on the website do not reflect the change to the slugs in the database. The links (post slugs) are somehow cached. We need to truncate the appended “-3” so that the articles are accessible from legacy links to said articles in emails, on other websites, within Facebook, etc.

We have tried uploading an updated version of the theme with the hope that doing so would reset the cache. All of our efforts so far have not yielded any fruit.

How do we reset the cache once we programmatically remove the appended “-3” from each article’s slug in the post table of the database?

You have two choices:

  1. Remove the -3 from the slug using the API, meaning each URL will regenerate properly in turn
  2. Remove the -3 via the DB and then restart Ghost.

It is generally frowned upon to make changes directly to the database. Ghost has a lot of code for handling things exactly like this, and it’s very easy to do things in a way that doesn’t bypass Ghost’s internal handling by using the API.

If you do change things “underneath” Ghost - the only way to ever resolve it is restart Ghost and let it refresh itself.

1 Like