Is there a way to sort category/taxonomy list based on number of posts it contains?
regards, Desizner
<?php
foreach (get_categories('orderby=count&order=DESC') as $category )
{
/*Some stuff here*/
}
?>
For more details take a look at: https://developer.wordpress.org/reference/functions/get_categories/
Currently (September 2017) I also do it using wp_list_categories (as Ryan B) but with the following code:
<?php wp_list_categories( array(
'orderby' => 'count',
'order' => 'DESC'
) ); ?>
You can use get_categories() function and pass one of these values in 'taxonomy': 'category' (to get only categories) or 'post_tag' (to get only tags) or even remove this key and it'll get both. Bellow we're ordering by posts counting on each category DESC.
<?php
$categories = get_categories([
'taxonomy' => 'category',
'orderby' => 'count',
'order' => 'DESC'
]);
foreach ($categories as $category) {
// Do something
}
?>