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!
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.