You should be able to use the standard get_post_meta() function to fetch the data from your meta fields, and it’d handle the unserialization for you. Afterwards, it’d just be an array of items from your repeatable/group fields.
Looking at the “your function” section, it’s serializing the already serialized data. You’re getting 1 string saved, that represents serialized data. I have to believe you’d have to unserialize twice to make any use of the content.
Long story short, use the WordPress post meta functions to grab your CMB2 content and you’ll be in good company. No need to roll your own solutions.
Hi Michael!
I am using CMB2 to save data in repeating fields on the admin side.
But i need send data in the site front end too, via XML data loading.
This is my problem, sorry if i’m not able to explain.
Hi!
Solved!
WordPress convert array in serialized data auto! Thanks!
Not sure what to tell you regarding the XML data loading part. I can say for certain that you should be able to get the data on the frontend using PHP and WordPress functions.
Using the default “Sample Page” example that new installs ship with, say you had your fields set up and data saved for that page. This could be done from the page.php template file.
$mydata = get_post_meta( get_the_ID(), '_cpf_requerente_1', true );
the $mydata variable would hold an un-serialized array of your data stored in _cpf_requerente_1s that you could loop over and manipulate. I have to imagine you could even utilize it to generate some xml of some sort, but I am not sure what the exact requirements are for that part.