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

I'm building a custom index loop that just uses query_posts at the moment.

The issue is that inside The Loop, I have to then query for the post meta data (with get_post_meta), which I believe has to query the DB each time it's called. Is there any way I can pull the meta data with the query_posts? I'd need most if not all of the meta data stored for each post.


share|improve this question

Actually, you're a mistaken on a couple of points here.

1. Don't use query_posts()

This function is meant for modifying an existing query, not performing a standalone query. You should either use get_posts() or a new instance of the WP_Query() class to perform your query for the custom loop.

Here's some further reading on query_posts():

2. get_post_meta() doesn't hit the DB repeatedly

When you do run a post query, WordPress retrieves not only the post, but also the post meta. We use a built-in object cache to insulate the database from repeated requests for the same information. If you're using a caching plugin on top of this, you can also receive the benefits of server-side tools like memcached.

You can read about the object cache in the Codex. Take a close look at the list of persistent cache plugins at the bottom of the page, not only will they make get_post_meta() calls lighter, they'll speed up other elements of the site as well.

share|improve this answer
Well perfect, I've never seen much on the caching in Wordpress, and didn't know it caught post meta, that's really good to know. And I'll swap out query posts too, thanks! – Ben Jul 14 '12 at 0:17

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.