Tell us what you are trying to do?
Hello, I have a content template that I'm using to display our internal decks / presentations. Everyone loves it, except that people were hoping to store revisions of one of the fields.
Specifically, this custom post type has a field, "Working File" that contains the original deck. We're hoping to set this up in a way where the system always references the most recent version of this "working file" post field, but we could potentially get a list of previous uploads of the working file.
I know this may sound a bit complicated, pls let me know if I need to clarify.
Thanks!
Is there any documentation that you are following?
No
Is there a similar example that we can see?
Dropbox (has older versions of files when u upload)
What is the link to your site?
hidden link
Hello, WordPress's built-in revisions feature dropped support for custom fields in the past, so unfortunately there is no built-in way to achieve revision / version control including custom field values. There are some plugins and custom code snippets out there that claim to be able to restore that feature, but I can't say whether or not they are fully effective:
https://github.com/adamsilverstein/wp-post-meta-revisions
Instead, you could create your own custom solution that implements a post relationship to create a child post containing this custom field value. Each time you want to change the deck, you would create a new child post containing the new deck in that custom field. To display the latest deck, you would create a View of these child posts with a limit of 1 post. You could sort that View by publish date to always display the most recent deck in the View, or you could implement some other custom sorting system based on an automated version number or something custom. If you wanted to be able to easily restore an older version of the deck, you would need to implement some type of workflow to move an older version to be the first result of the View, either by changing the publish date or changing that custom version number somehow.
So the solution depends to some extent on how comfortable you are with custom code, and the effectiveness of the available 3rd-party prebuilt solutions. Let me know if you have questions about these options, and I can provide additional guidance if possible.
Hello Christian,
Thank you for your reply. Out of the options you presented, I think this one sounds most promising:]
"Instead, you could create your own custom solution that implements a post relationship to create a child post containing this custom field value"
I *think* I know what you're talking about, but might you be able to elaborate a bit more, and / or provide links / documentation?
Thank you very much for this assistance!
Max
Sure, I was thinking about it like this:
- Create a new post type called "Decks" or something similar.
- Add a custom field to the Decks post type that will be used to store the deck information, basically the same as the Working File custom field you currently have implemented in the existing post type.
- Create a One-to-Many (O2M) relationship between the existing post type and the new post type. The existing post type will be the "One" side, or the parent. The new Decks post type will be the "Many" side, or the child.
- Anywhere you are currently displaying information about the Working File from the existing post type, you must replace that information with a View of the new Decks post type, and display the new custom field from that Deck post instead of the existing Working File field from the existing post type.
- To get started, you will edit each post in the existing post type and create one new child post in the new Decks post type. You should delete the Working File field value from the parent post and add it to the child Deck post field instead.
- Once you've transferred the existing fields into the new Deck post type, you can remove the Working File field from the existing post type to prevent confusion.
- To add a new Deck revision, you can edit the existing parent post and create a new Deck child post right from the parent post editor screen using the post relationship panel. Add the new deck file in the child post's custom field. The Views you have already set up will automatically update to show the latest deck information on the front-end of the site.
Some references for you to review below.
Displaying content in a View, ordering and limiting results in a View:
https://toolset.com/course-lesson/creating-a-view/
Post relationships - what they are, how to set them up, and how to display related content:
https://toolset.com/course-lesson/what-are-post-relationships-and-how-they-work/
https://toolset.com/course-lesson/how-to-set-up-post-relationships-in-wordpress/
https://toolset.com/course-lesson/displaying-related-posts/
If you need specific information about something, let me know where you have questions and I can try to fill in the gaps.