How to get post meta value and post in one query?

When query a post, I need not only the post but also the post_meta. But seems the post query and meta query can not be done together.

With WP_Query, I first get the posts, then, I need to do get_post_meta(get_the_ID(),'key',true)

Read More

Is this the way WP works? Or, is there a way to query both in one hit?

Related posts

Leave a Reply

2 comments

  1. When you do a query WordPress already gets the post_meta.

    Even though you are calling get_post_meta() It is not performing another query. It is retrieving the value from the post meta cache.

    Now if you don’t need the post meta you can set a flag that will eliminate the additional MySql query. To do this you set 'update_post_meta_cache' => false in your args.