I’m having a problem retrieving post_meta values that I have stored in an array. I use this for storing the array:
add_action( 'comment_post', 'add_food', 1 );
function add_food(){
global $post;
$testvalues = array('bread', 'cake');
update_post_meta($post->ID, 'food', $testvalues);
}
and this for retrieving it:
add_filter('the_content', 'print_food');
function print_food($content){
global $post;
$custom_fields = get_post_custom($post->ID);
$food_field = $custom_fields['food'];
$content .= $food_field[0];
return $content;
}
however, this is added to the content of my page:
a:2:{i:0;s:5:”bread”;i:1;s:4:”cake”;}
The technique works fine for the comment_meta. What am I doing wrong here?
Aha! I think I found your answer. Two facts:
Therefore, this [untested] snippet should get you your food array as an array rather than a serialized string.