What is the efficient way of getting meta values of a custom post type in wordpress?
So far there are two ways I know.
First is to create a custom query like:
SELECT ... (SELECT meta_value FROM wp_postmeta WHERE post_id = wp.ID and meta_key
= 'fname') as fname .. FROM wp_posts wp INNER JOIN wp_postmeta pm ON pm.post_id
= wp.id WHERE post_type = 'customer'
$meta_values = get_post_meta($post_id)
then use a foreach loop
All WordPress post meta data is internally cached, running your own SQL query will not have this benefit (unless you implement your own caching).
get_metadata(), which in turn calls
wp_cache_get(). And from that point on, where it goes inside the class
WP_Object_Cache, I got lost...
Anyway, I've read from multiple sources (WordPress Development, WP Forums, wp-hackers mailing list) that using
get_post_meta is the way to go.