Support Forum
Support › MB Custom Table › Custom Table with Group fieldsResolved
What is the proper way to create a custom table and store data for custom fields that contain groups with nested fields?
I have created a meta box with the Builder. The meta box has a number of groups that each contain one or more fields.
When I choose not to use a custom table, WordPress stores each group's data in the wp_postmeta table. The group's name becomes the meta_key and the group's data is serialized (I believe) and stored as text in meta_value.
In my attempt to store the data is a custom table I tried to emulate that by creating columns for each group like:
MB_Custom_Table_API::create( "{$prefix}table_name", array(
'group1' => 'TEXT NOT NULL',
'group2' => 'TEXT NOT NULL',
'group3' => 'TEXT NOT NULL'
) );
But that does not seem to work, so now I wonder if there is a different way I should be doing it.
I created a more simple test and had success saving a single text field contained in a group. So now I wonder if there's something else going on.
Test Case:
group (id: group)
-text (id: text)
Code:
MB_Custom_Table_API::create( "{$prefix}testing", array(
'group' => 'TEXT NOT NULL'
) );
Setting that group to cloneable (to emulate the design of my production meta box has no affect on saving the data successfully - a good thing!)
I'm continuing to look into this.
Well, I am not exactly sure what happened, but I basically started over:
Weird, but I'm happy! If you want to know more details just reach out.
Hi Purdue,
Glad that it finally worked for you. To save groups to custom table, treat it like a normal text field. And ignore all the sub-fields in the group as they will be serialized and store in one column in the DB (the column of the group).
If you find any trouble, please let me know.