Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a query that can only be done using straight SQL, but I need to loop through the returns as a set of posts. As I understand it, WP_Query automatically gets all the metadata for all the posts retrieved, and caches it for when get_post_meta is called. But since I have to use wpdb->query, I was wondering if there was anyway I could call another function after it with a set of like post ids, which would cache all their meta; this way I don't hit the database for every post in the loop.

Right now I am actually inner joining the fields I need from the post_meta, but this just seems like a bad (and messy) idea.

Thanks,
Max

share|improve this question

1 Answer 1

I did a lot of digging into wordpress, and it looks like WP_Query ends up calling (indirectly) update_postmeta_cache($postIDs); which looks like it is exactly what I need.

Hope that helps somebody else out. In 3.5.1 it's located in wp-includes/post.php#2735.

share|improve this answer

Your Answer

 
discard

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.