• Resolved Simon Frntic

    (@sim33on)


    I use taxonomy select field in user profile fields. It works ok.

    My question is, when I look in database in table usermeta it’s written:
    meta_key: _cmb2_user_delovna_podrocja
    meta_value: a:1:{i:0;s:1:”4″;}

    Cause in my app I’ll have sometimes to put in values programaticly I need to know what kind of format this is. I know s:1 is number of characters in semicolons and :”4″ is taxonomy ID, but what is a:1{i:0

    Is there any wp or cmb2 function that I can use to convert ID to this format and then write it to database.

    https://ww.wp.xz.cn/plugins/cmb2/

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

    (@tw2113)

    The BenchPresser

    The content is being stored as serialized data.

    Essentially “a:1:{i:0;s:1:”4″;}`” is equating out to the following.

    The value is an array. In that array, the index key 0 is storing an array value of 4, which is a string. The 1 after the “s:” indicates that the string has a character length of 1.

    a = array
    i = index
    s = string
    (there are others for serialization marking, but I’m sticking to the example above).

    If you had a higher taxonomy id, say 341, the stored value would be “a:1:{i:0;s:3:"341";}

    The add/get/update meta functions do the serialization/unserialization for you, so if you were to do a get_post_meta( get_the_ID(), '_cmb2_user_delovna_podrocja', true ); call, you would, or at least should, receive the actual array back, and not the serialized version. You could then loop over it and do whatever you needed with those IDs.

    Hopefully that makes sense.

    Thread Starter Simon Frntic

    (@sim33on)

    This makes sense and that’s was what i needed. Thank you for answer.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘taxonomy select variable format in DB’ is closed to new replies.