0

Is there an efficient way to get some posts with (some of) their custom fields in one go?

I have a custom post with some custom fields and would like to create an overview page where I display all posts in their respective category. I need the custom fields because there is info about how to display the posts in this overview (icon location, alt text etc.)

I don't want to just get a list of posts and then get the custom fields for every single one of them using a loop producing a ton of queries.

I know I can cache the result until a post changes but it would be nice if it wasn't necessary at all.

So is there a way to get posts with their custom fields or at least a way to get the custom fields of several posts at once or do I have to write my own query to achieve that?

1 Answer 1

0

Meta fields are heavily cached. Depending on your configuration and specific query, it is likely that WP_Query calls update_post_caches() which trickles down to update_meta_cache() for queried posts.

Most of the time you don't need to worry about this, until you determine that it is real bottleneck in some way (like profiling code).

1
  • okay, I'll do a profiling after the code is finished and then we'll see. thanks for the moment
    – Dehalion
    Commented Jun 16, 2013 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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