Get Taxonomy Terms by Count

This function returns an array of taxonomy term objects. It is much like taxonomy_get_tree(), and it does in fact use this function. We had a client that wanted a grid of product categories with an image for each term, but only for terms that have at least X associated nodes. This problem was solved using the function below, as well as another custom function to alter the views query (I’ll post about this later).

I’d like to also mention that I toyed with the idea of adding a $max_items variable. It’s simple enough to do, but I figured (maybe incorrectly) that you wouldn’t ever need to say, “Give me all terms that have between 10 and 30 associated records.”

Leave a Reply

Your email address will not be published.