WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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)

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

share|improve this question
up vote 6 down vote accepted

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.

share|improve this answer
So, how to get the meta value when get the query results? – Jenny Oct 1 '12 at 4:14
The meta_value is retrieved when you get the query_results. You have to call get_post_meta() just like you have to call the_content() – Chris_O Oct 1 '12 at 4:23

You can also use get_post_custom() to return an array of all meta values so that you don't have to use the meta_key for each.

I was not aware that WP cached the meta data, thanks Chris_O.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.