Storing arrays in post_meta
-
When I ask for a post’s meta value, it comes as an array or a string.
Can I store an array of values?
For example, if I have an array
$postIDs=array(21,47,81,32)
, can I store it withupdate_post_meta($post_id, 'postIDs', $postIDs)
?Currently, I’m joining the array into a string and storing that.
$postIDstring = implode(",", $postIDs); update_post_meta($post_id, 'postIDs', $postIDstring);
Then I’m extracting it:
$postIDstrings=update_post_meta($post_id, 'postIDs');
$postIDs=explode(",",$postIDstrings[0]);
How does it work?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Storing arrays in post_meta’ is closed to new replies.