Cmb2: Getting data from multicheck

Created on 9 Mar 2015  路  6Comments  路  Source: CMB2/CMB2

I need a pointer on how to get the data from the multicheck

I am guessing I need to use a foreach but if I do var_dump($array) I get

array(1) { [0]=> string(1) "3" }

Which doesn't tell me what I need to pull out of the array in the foreach, can anyone spread any light on the best way of doing this?

All 6 comments

Data from a multicheck (or select, group, etc) is stored as a serialized array in the meta value. So, to use it you need to put it in a foreach and use the data. Something like this:

$array= get_post_meta( $post_id, 'prefix_meta_key', true );
if( $array ) {
    foreach( $array as $key => $value ) {
        echo 'This is the value: ' . $value . ' for this key: ' . $key; // or whatever else you want to do with the data
    }
}

Cheers Josh

Unfortunately your code didn't work Josh but trial and lots of searching did, and used:

get_the_term_list( $post->ID, 'taxonomy', '', ', ' );

@gareth-gillman I think you neglected to mention you were trying to get the data from a taxonomy_multicheck which is definitely different than getting data from a standard multicheck.

This one should help https://github.com/WebDevStudios/CMB2/issues/212 but get_posts what do You want.

Matt

Thank you @joshuadavidnelson! Your response helped me out with my own project.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gorirrajoe picture gorirrajoe  路  4Comments

bomsn picture bomsn  路  5Comments

tw2113 picture tw2113  路  8Comments

noquierouser picture noquierouser  路  8Comments

jquimera picture jquimera  路  8Comments