I would like to display in the categories section of my sidebar a list of only x amount of categories (say, a limit of 10), sorted by number of posts. So, for example, if I've got 10 posts under the "music" category, 5 in "television" and 2 in "movies", it'll display them in that order. I managed to construct a SQL query that displays the categories in order, but I have to use wordpress.wp_post2cat in order to do it:
select category_id, count(*) as "count" from wp_post2cat group by category_id order by count desc;
Does anybody know of a way I could construct a custom function based on list_cats() or wp_list_cats() that could accomplish this?