[wp-hackers] Get terms from wp_query when using tax_query

Jeremy Clarke jer at simianuprising.com
Mon Feb 17 14:55:24 UTC 2014


On Wed, Feb 12, 2014 at 11:22 AM, Filippo Pisano
<filippo.pisano at gmail.com>wrote:

>
> I was wondering if there is a smart/quick way to obtain all terms attached
> to a post when querying posts through WP_Query();
>
>
The terms for all posts in a query should be fetched while WP_Query is
going through it's various motions. They are saved to the object cache so
you won't find them in each $post, but once a post has been queried you can
fetch it's terms for free (no db queries, fast access to object cache).

I think that answers your question. Yes, you'll have to loop through all
taxonomies you are interested in to act on them, but it shouldn't be any
harder than looping through a $post->terms array, and avoids cluttering up
WP_Query objects with tons of metadata.

-- 
Jeremy Clarke  • jeremyclarke.org
Code and Design • globalvoicesonline.org


More information about the wp-hackers mailing list