Looking for a way to include custom fields in the output of WP_Query. I am managing a site where nearly every post type has a lot of custom fields defined and it would be much nicer not to have to run get_post_custom in almost every loop.
Leave a Reply
You must be logged in to post a comment.
You may want to hook somewhere in the gazillion hooks available in
wp-includes/query.php
.I would suggest something like this:
In this way you will always have your posts custom fields at hand in your
$post
object without having to bother to look for them every time you are setting up a loop. From now on, you can just access them using$post->custom_fields
as amulti-dimensional array
.WP_Query
let you query posts based on key or values from the custom fields if you would like to get multiple values from custom fields usewpdb
you can read more about here.