[wp-hackers] Get meta value with foreach

Paul paul at codehooligans.com
Wed Aug 18 01:46:19 UTC 2010

Have you checked your parameters against the Codex? 


(boolean) (optional) If set to true then the function will return a single result, as a string. If false, or not set, then the function returns an array of the custom fields. This is not intuitive. For example, if you fetch a serialized array with this method you want $single to be true to actually get an unserialized array back. If you pass in false, or leave it out, you will have an array of one, and the value at index 0 will be the serialized string.
Default: false
You are passing false for the third parameter. Maybe you should be passing true to return a non-array.


On Aug 17, 2010, at 9:42 PM, mailapera wrote:

> I get this function to get a custom meta value for each post called by the
> function, but for some reason the only output is the word "array" for each
> post instance.
> foreach ($my_posts as $post_id) {
>            $p = get_post_meta($post_id, 'email', false);
>            echo "$p";
>        }
> I don't get it
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers

More information about the wp-hackers mailing list