Tell us what you are trying to do?
I have 5 custom post types and they have relationships between them.
I need to have record history of any modification it's made to the post type and their relationships.
There is a way to handle this?
Unfortunately the record keeping would need to be implemented completely by custom code. While wordpress core itself does keep a revision of the posts, it doesn't keep any Meta data. This include custom fields and the post relationship information.
For any records to be kept you will need to write some custom code to record these.
Ok then if i make a new custom post type, where i want to create the history by manual save, how can i copy the data from one table to another?
Let me explain better, i have this 5 post type, and in a view i show all the information with relationship, and i want to make a "save" button, that will create a record situation of this information to a new table "post type history". There is a way to pass the fields to the new table?
Here we are talking about 2 different things a custom Post type and a Database Table.
Hopefully i'm correctly assuming that when you say "Pass field to a new table" you are referring to passing the values to this new post type.
If so then you should be able to. Where are you creating the posts on the frontend or the backend ? The main issue is that relationship fields are a little special so in order to create a history for this I would recommend storing the value i.e the ID of the field in a single line field, however this can easily become quite complex.
Achieving this can become quite cumbersome and requires a good amount of PHP knowledge to manipulate the data to programatically create the post and populate that newly created post with the field values from the currently viewed post. Also there will need to be some form of history management.
The reason is that your new post type can quickly become over a thousand posts given each time one post is updated an entry will be created. So if a use hits the update but 5 times then 5 history posts will be created.
Hi Shane,
yes i mean pass the values to the new post type. I'm creating the posts on frontend. Yes, i was thinking to store the values on the new post type, not creating new relationships. The update will be saved manually, i mean when someone makes changes to the post type, then he has to press a button "save". For solve the problem of hits many time the "save", it's to check last input, if no variations to the filed, then no new post created.
Before the update to the post is saved to the database you can check if a value has changed, this is going to be a bit tricky given that you will need to check the post against its existing values, this means checking each custom field value against its stored value in the database.
However this would should be suitable enough for you to perform your action.
Hi Shane,
thx for you answer but i don't need to intercept on form completion. My user will modify the fields he needs, and this could be more relationships and then he save the fields situation to the new post type. With this hook #Cred_before_save_data i have to perform on forms update, i'm right? In this case will create a new post type "history" for every single post type. I need a post type "history" that collect in once all the 5 post types value fields!
With this hook #Cred_before_save_data i have to perform on forms update, i'm right? In this case will create a new post type "history" for every single post type.
You can use the Cred_before_save_data hook to compare the current value being sent and the previous value to see if they are the same and then create a post in the History post type. This is the way I see of doing it.
I need a post type "history" that collect in once all the 5 post types value fields!
I understand the need of the History post type as this is where you will be storing the previous version of the updated post, however i'm not sure what is meant by "all the 5 post types value fields".
Is it that you have 5 different post types, so you're thinking of storing the history of the 5 different post types in 5 different history post types?
Based on your diagram, you will be pulling relationship data to set in the history.
What you can do is to create single line custom fields for each of the Relationship in the History works post type.
What i mean by this is that a custom field is to be created for Mens, Vehicles, Radios, Tools. Then when a work is updated, you will pull the current relationship data from that Work post type and create a History Works post based on the current data of the post.
"What i mean by this is that a custom field is to be created for Mens, Vehicles, Radios, Tools. Then when a work is updated, you will pull the current relationship data from that Work post type and create a History Works post based on the current data of the post."
How can i achieve this??? I mean, create the custom fields on "history custom post": no problem! How can i get the values for then insert in the history post?
The toolset_get_related_post function essentially returns the post id of the related post. This function is to be used with the relationships that are one to one.
While coding this for you is out of the scope of our support forum. The most I can do is to point you in the direction of the functions that you will need to use to get this working.