• Resolved Angelo Rocha

    (@angelorocha)


    Hi!

    How to CMB2 store data from repeatable or group fields in DB? I need help to store data in front end from same way…

    I’m trying use “maybe_serialize()” function, but not success, i need save a array…

    How to CMB2 save data in my DB:
    Meta Key: _cpf_requerente_1
    Meta Value: a:2:{i:0;s:14:”608.198.523-76″;i:1;s:14:”608.198.523-76″;}

    How to my function save data in my DB:
    Meta Key:_cpf_requerente_1
    Meta Value: s:84:”a:3:{i:0;s:14:”608.198.523-76″;i:1;s:14:”608.198.523-76″;i:2;s:14:”010.964.463-83″;}”;

    Help!

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    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.

    Thread Starter Angelo Rocha

    (@angelorocha)

    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.

    Thread Starter Angelo Rocha

    (@angelorocha)

    Hi!

    Solved!

    WordPress convert array in serialized data auto! Thanks!

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    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.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to CMB2 store data’ is closed to new replies.