[wp-hackers] limiting tag clouds to custom post type
wp at andrewnacin.com
Wed Jun 8 18:17:36 UTC 2011
On Tue, Jun 7, 2011 at 2:05 PM, Otto <otto at ottodestruct.com> wrote:
> Post types are part of the posts themselves. So you have to query
> against the posts table.
> The only "efficient" way to do it is going to be with a custom SQL
> query. Join the posts table with term_relationships, term_taxonomy,
> and terms, selecting based on the custom post type.
Actually, what you could do is rely on WP_Query's term caching abilities.
When WP_Query is run, it triggers three main queries: grabbing everything
relevant from wp_posts, wp_postmeta, and wp_terms/wp_term_taxonomy.
You could then loop through and calculate all of the term data -- which
would all be in cache -- and then build a tag cloud.
And all you're running is three queries at O(1) complexity. Much more
efficient than the code there, and more stable than a direct query.
More information about the wp-hackers