Support Forum
Support › Meta Box Group › Migrating data to a group, formatting breaking
I have an existing metabox layout which I'd like to convert to use the new metabox groups.
Looking at the way the data is stored I've tried to replicate this. I have the array...
Array
(
[0] => Array
(
[year] => 2013
[title] => Test
[wins] => 1
[podiums] => 2
[poles] => 3
[description] => test description
)
[1] => Array
(
[year] => 2014
[title] => Test Title 2
[wins] => 1
[podiums] => 2
[poles] => 3
[description] => Test Description 2
)
)
*apologies for dodgy format, text editor doesn't like code placements
When I try to save this in update_post_meta it loads the data into their correct fields, but each cloned field is nested within each other, rather than there being a linebreak between.
Markup of the fields after the manual import
Real data array being passed into update_post_meta (array has 20 or so items, I've clipped the bottom off)
View of the editor (some fields intentionally blank). No line break to signify the spit groups between the description field and the year field.
After the groups finish, the line breaks are visible batched together.
Hi,
How did you convert existing data to group of fields?
I essentially wrote it out again from scratch.
Plucked out the data I wanted from the previous fields. Remapped it onto a new array and saved that with the same key.
As far as I can tell everything was in the right format.
So it's solved now?
If you need me for anything, please let me know.
Sorry, no, it's not solved yet. You asked how I converted existing data to the new group of fields.
Between this and my initial post I've explained how I've done this however it doesn't work as it ends up nesting the data inside itself as explained above.
Hi,
I've tested with your data and here is my result:
1. I use the following code to add data to a post:
https://gist.github.com/rilwis/452dec0295484a455875#file-add-data-php
2. Then I register a meta box with following code:
https://gist.github.com/rilwis/452dec0295484a455875#file-register-meta-boxes-php
And here is final result:
I think it works for me. Can you check the code to import data and register meta box again? If you need any help, please let me know.
Ok, i think I've found the issue. It wasn't the data migration that was the problem. That just made me notice it.
It was the Columns inside the fields. I'd perhaps tried too much at once.
When I commented out the 'columns' key for each field it worked as expected.
$meta_boxes[] = array(
'title' => 'Pedigree',
'pages' => array( 'drivers' ),
'context' => 'normal',
'priority' => 'low',
'fields' => array(
array(
'id' => 'pedigree_group',
'type' => 'group',
'name' => 'Group',
'clone' => true,
'fields' => array(
array(
'name' => 'Year',
'id' => 'year',
'type' => 'text',
'columns' => 2,
),
array(
'name' => 'Title',
'id' => 'title',
'type' => 'text',
'columns' => 10,
),
array(
'name' => 'Wins',
'id' => 'wins',
'type' => 'text',
'columns' => 4,
),
array(
'name' => 'Podiums',
'id' => 'podiums',
'type' => 'text',
'columns' => 4,
),
array(
'name' => 'Poles',
'id' => 'poles',
'type' => 'text',
'columns' => 4,
),
array(
'name' => 'Description',
'id' => 'description',
'type' => 'textarea',
'columns' => 8,
),
),
),
)
);
So sorted for now but columns inside a group would be really useful for making this really slick.
Great job either way though!
Thanks
Glad to hear that the data migration works well. It'd be a pain if we loose data.
I tried again with your code and I see that the last field doesn't have enough columns (8 while it should be 12 to fill in the row). It's a note that each row must have enough 12 columns, here you have first row with 2+10 columns, 2nd row with 4+4+4 columns and 3rd row has only 8 columns.
I tried changing 8 to 12 and it works fine to me: