We often use a relation between pages. But how to keep the data consistent?
Example: We have a pages field with page1 selected, but after some time we delete the page1, but it is still referenced in the related in the content.
How can we clean this? Is there an example?
In this case, it’s not really relevant, because the page then will not be shown on the frontend and will be automatically removed from the list when you visit the page the next time and update.
What is more critical than a deleted page is a renamed page slug, because in this case, the relation between the pages will be removed. The best method against this would be to store an autoID(via the AutoId plugin), but this currently doesn’t work with the pages field.
So three options:
- When a page is renamed, go through all pages with the stored old value and change the reference via a hook
- Don’t use the pages field but a multi-select field in combination with the AutoId plugin
- Create a custom pages field that stores the AutoId instead of the id
Support for using a custom value in the pages field is planned, but not yet available.
Thank you for the good explanation. Multi-select field + AutoId
AutoID is a good option when lot of pages and we need integrity, but also requires to make a connection to a SQLITE db.
In some simpler websites we will still use the pages select field (without the AutoID plugin) Is there no cleanup script that looks for not existing references?
As I wrote above, the problem is not the non-existing ones but the changed ones.
There is no out of the box script, but you can set up your own. I think it makes the most sense via a hook.
You can create your own AutoId plugin without database. All it needs is a page.create:after hook that auto-fills a field with a unique identifier.