Support

Account

Home Forums General Issues Want to use get_post_meta instead of get_field for array Reply To: Want to use get_post_meta instead of get_field for array

  • OK I got it worked out (whew!)…thanks to @ericnkatz who got me to dig deeper and read more about serialized strings as arrays

    SO what I had to do was setup the variable using ‘true’ to indicate that the meta data is, in fact, a string not an array (yes it’s multiple values for the key but it’s all stored as a single string since as mentioned in my original post it’s a series of checkboxes for one key)…..THEN run a foreach on the results. It didn’t work before because I was doing it bass-ackwards.

    The right way is this:

    $myvalues = get_post_meta($post->ID,'my_key',true); //using 'true' here is vital
    foreach ($myvalues as $myvalue) { echo $myvalue.', '; }

    Thanks!