If you need to sort your taxonomy query by the number of items with that taxonomy assigned, it is quite simple — sort by count.
$query_args = [
'taxonomy' => $tax ?? 'category',
'orderby' => $order ?? 'count',
'order' => $dir ??'DESC'
];Since you don’t want different queries, you can use the query arguments like any other query.
Leave a Reply