Support Forum
Hi there!
I have a question regarding the way data is stored in the database in certain type of fields.
My question is specifically directed to “group” where we can group multiple fields and then use the “clone” feature. I love to use it but I’m concerned about the way the data is stored in the database which is a serialized array.
Fields like “checkbox list” or “images_advanced” store the data in multiple meta fields in the database which is the “native” WordPress way of doing things and I like it. The data is nicely stored in the database and I can perform simple EQUAL query.
However, since groups are stored as serialized arrays, such query is not possible. Instead, we need to do a “LIKE” that is much, much worse in terms of performance.
I was recently inspecting the ACF plugin and I noticed that their repeater plugin stores data in separate meta fields.
Is there any way to recreate it in Metabox.io?
Regards!
Hi,
Thank you for contacting us. Hope you are well today.
Currently, the Meta Box plugin only supports to save the group in the database as a meta and the fields inside as the serialized string. But you can use the settings
'clone_as_multiple' => true,
to save the group or other fields (not in a group) into many rows if it is cloneable.
For more information, please follow this guide
https://metabox.io/introducing-clone-as-multiple-feature/
Hope that helps you something.
If you use clone-as-multiple and want these queries to be really fast, use covering indexes:
http://www.unofficialmysqlguide.com/covering-indexes.html
Thanks
Hi guys!
Thank you for your responses. I love the responsiveness in this community.
Long: Yeah, I’m aware of the clone_as_multiple option and it’s actually what prompted me to ask this question. I noticed that at first, cloneable fields were stored in a serialized way and that option was added further on with the default value set to false for backwards compatibility. That made me think that the way groups are stored is also a subject to change and improvement. Do you know of any plans regarding this matter?
Thanks a bunch!
Hi prafgon,
The clone_as_multiple
is available for all fields, not just group. So it's nice to make query for those fields. But due to the fact that group already store group value as a serialized array of all sub-fields, this option doesn't change the serialization issue.
I'm afraid we haven't got a plan for moving from serialization for group in a near future. I'll check the ACF repeater to see if we can learn from them. Thanks a lot for the reference.