Assuming you’re retrieving the posts using a standard WP_Query in some manner, then the postmeta data is automatically retrieved for all the relevant posts and cached in memory. When you later call get_post_meta
, the data is simply returned from here.
So honestly, it doesn’t make any significant difference which approach you take. The get_post_meta
function isn’t making database calls unless the data isn’t in memory already.
If you’re making a WP_Query and have no need to cache the postmeta info, you can set the update_post_meta_cache
argument in the query to false. Similarly, you can set the update_post_term_cache
to false to prevent it from caching relevant terms from the taxonomy system as well. These can speed up a query for specific cases where you know that you don’t need the meta/terms in advance.