Custom fields exist already...
Support › MB Revision › Custom fields exist already...
- This topic has 10 replies, 2 voices, and was last updated 7 years, 4 months ago by
Bonnie.
-
AuthorPosts
-
November 13, 2017 at 6:19 PM #7377
Bonnie
ParticipantI have just purchased the MB Revision plugin as I would like to track revisions to the posts contained within an existing Custom Post Type. The fields exist already (they were created using the WP Types plugin) and all I am wanting to do is track revisions.
Can someone please give me an idea of the syntax required to add existing CPT to the metabox code in functions.php? The only code I can find is to create new CPT...
Thank you
BonnieNovember 15, 2017 at 11:49 PM #7403Bonnie
ParticipantCan anyone help please?
November 16, 2017 at 12:12 PM #7409Anh Tran
KeymasterHi Bonnie,
The syntax to add fields to existing custom post type is nothing different from new custom post type. In the meta box settings, just add
'post_types' => array( 'your_post_type' )
. Please check this docs for more info.Please note that if the fields already exist, then there's no way to track their previous values. The extension can track values from now on.
November 16, 2017 at 3:59 PM #7412Bonnie
ParticipantHi Anh.
Unfortunately that link is broken - do you have the correct link please?
Thank you
November 16, 2017 at 5:12 PM #7415Bonnie
ParticipantI've found another page with documentation. I still can't work it out, though.
When I add an existing field, it brings it up as an additional meta box below my existing custom fields. What I want to do is track the changes made to those existing custom fields, not store new values in new boxes at the bottom. I am a little bit confused...
November 16, 2017 at 5:40 PM #7417Anh Tran
KeymasterI've just fixed the docs link. There was a problem with my HTTPS setup.
Just curious, how do you create custom fields? Do you create with the WP-Types plugin?
November 17, 2017 at 5:37 PM #7433Bonnie
ParticipantThank you for fixing the link!
Yes, they have been created with WP-Types. So they already appear on the post type - I don't want to add them again, if that makes sense. I just want to track their changes.
To give it a bit of context, I maintain the website for a large hospital with a number of laboratories. I have a custom post type called "Lab Tests".
This has the following fields, all created in WP-Types:
Sample Unit (e.g. mL)
Sample Size (e.g. 40)
Sample Type (e.g. Blood, Urine, etc.)
Special Timings (e.g. must be tested within 48 hours)
Patient Preparation (e.g. Patient must refrain from vigorous physical activity for 48 hours beforehand.)I want to make sure that if any of the above values is changed, that change is tracked as a revision - and it shows the revisions screen like it does for regular pages (which use the editor) e.g. clearly showing that Sample Size has been changed from 40 to 50.
Does this make sense?
Thank you.
November 17, 2017 at 8:01 PM #7438Anh Tran
KeymasterHi Bonnie,
Thanks for the info. That helps a lot understanding your situation.
In this case, I’m afraid to tell you that the MB Revision only works with custom fields made by Meta Box, not made by other plugins such as WP-Types. So my suggestion is you can rewrite the code to transform fields created by WP-Types to Meta Box. If the number of fields are not large and fields are not complicated, I think you can do that simply by following the instruction in the link I posted in the previous reply.
However, that depends on how WP-Types saves data in the database. If it’s compatible with the default WordPress behavior of storing post meta, then the transformation will be easy. This is how Meta Box saves data in the database.
November 17, 2017 at 9:13 PM #7439Bonnie
ParticipantOh no! I didn't realise when I bought it. I don't think I have the technical knowledge to do that... yes, I believe WP-Types metadata is created in the exact same way, from what I have read online. However I wouldn't have a clue how to rewrite the code...
November 18, 2017 at 6:48 AM #7445Anh Tran
KeymasterCan you send me an account admin via the Contact page? I can look at that for you.
November 23, 2017 at 10:13 PM #7550Bonnie
ParticipantHi Anh
Yes, no problem.
Thank you.
Bonnie -
AuthorPosts
- The topic ‘Custom fields exist already...’ is closed to new replies.