SELECT i.image_category_id id, c.category_name name, COUNT(1) count
FROM chv_images i
LEFT JOIN chv_categories c ON c.category_id = i.image_category_id
WHERE i.image_category_id IS NOT NULL
GROUP BY i.image_category_id;
Do please note that this is an expensive query. Don't call it on every request.
Thank you @Rodolfo for your answer. Can you tell me in which file I have to put the code. And that's where I can see the number of images by category as in the picture above.
You must execute that query using CHV\DB. I must insist, DO NOT call that query on every request. It will eat like 2 seconds of request time and it could compromise your server (ddos).
PHP:
$fetch = CHV\DB::queryFetchAll('
SELECT i.image_category_id id, c.category_name name, COUNT(1) count
FROM chv_images i
LEFT JOIN chv_categories c ON c.category_id = i.image_category_id
WHERE i.image_category_id IS NOT NULL
GROUP BY i.image_category_id;');