1

Is it possible to return taxonomy/term information for posts along with the posts themselves when querying with get_posts?

I have around 150 items I am querying so I don't want to loop and pull each individually.

  • 2
    WordPress will cache all terms for the query by default. Calling get_the_terms etc. within the loop with not hit the database – TheDeadMedic May 22 '16 at 0:11
  • @TheDeadMedic Even though it's a simple answer, you should post this as an answer so it can be accepted and not come up in the unanswered list :) – Tim Malone May 22 '16 at 6:40
1

WordPress will cache all terms for taxonomies attached to all post types in the query result set by default - well, so long as you haven't set either cache_results or update_post_term_cache to false (codex).

So calling get_the_terms etc. within the loop will not hit the database. However, wp_get_object_terms will hit the database as it by-passes WordPress' object cache.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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