I need to get the terms for 2.000 posts. How can I do this without making 2000 queries? Is it possible to get terms of the post in the post_object with a filter or something similar?

wp_get_post_terms($mobile_id->ID , 'brand',$args )

1 Answer 1


You can use the following SQL query

SELECT * FROM wp_posts a, wp_term_relationships b, wp_terms c WHERE a.post_status = 'published' AND a.ID = b.object_id AND b.term_id = c.term_id;

This will list all the post that is in the published state and then its terms.

You can add limits and offsets to limit the number of records.

  • I change my system to avoid the problem but I like your answer. Commented Jun 10, 2015 at 6:19
  • what did u change
    – Ashok G
    Commented Jun 11, 2015 at 9:53
  • I saved the data in php cache so I dont ask the db. Commented Jun 11, 2015 at 15:46

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.