How to store and retrieve a php array
-
Great plugin!
I have a php array that I store in a “Text” field of a custom post type. I use update_field(‘my_array’, $my_array, $post_id) to store the array and get_post_meta($post_id, ‘my_array’, TRUE) to retrieve it. This allows me to store and retrieve the array in the “Text” field called ‘my_array’.
However, when I save/update the custom post in the admin dashboard by clicking Update, ‘my_array’ gets converted to a string because it’s a “Text” field. As a result, get_post_meta($post_id, ‘my_array’, TRUE) then returns a string, not an array.
Should I be using a different field type than “Text” to properly store and retrieve a php array?
If that’s not possible, should I be using a “Text” field with json_encode(…) to store the array, and json_decode($json, true) to retrieve the array?
Any suggestions? Thank you
- The topic ‘How to store and retrieve a php array’ is closed to new replies.