[wp-hackers] Querying posts for all associated term_ids?

Paul paul at codehooligans.com
Sat Sep 4 21:09:17 UTC 2010


Just trying to understand the question here. Not a soluton. I've read through the StackExchange item. Still not sure I understand. 

You are just trying to get a distinct list of taxonomies for a given post_type. For example for the WP Posts you would find the categories and post tags. Correct?


On Sep 4, 2010, at 4:32 PM, Mike Schinkel wrote:

> Hi all,
> I am trying to figure out if it is possible to use the WordPress database API without having to add hooks to get the distinct list of term IDs from a given taxonomy that are associated with posts of a given post type? 
> I looked and could not find any thing available in WordPress core even though it seems that I must be missing something. Here's the SQL code that achieves what I'm after:
>  tt.term_id
> FROM wp_posts p
>  INNER JOIN wp_term_relationships tr ON p.ID = tr.object_id
>  INNER JOIN wp_term_taxonomy tt ON tt.term_taxonomy_id = tr.term_taxonomy_id
> WHERE 1=1
>  AND p.post_status='publish'
>  AND p.post_type='our_work'
>  AND tt.taxonomy='client_name'
> FYI this came up in me trying to answer this question:
> http://wordpress.stackexchange.com/questions/1140/
> Thanks in advance.
> -Mike
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers

More information about the wp-hackers mailing list