You can get the total category count for the store in Magento 2 by using the getCount() method.
You can fetch that information from
MagentoCatalogApiCategoryManagementInterface.
All you need to do is just create a simple Model class which will help you to retrieve the total number of the category. Code is as per below.
<?php
namespace MagemonkeyCategoryCountModel;
use MagentoCatalogApiCategoryManagementInterface;
class CategoryCount
{
/**
* @var CategoryManagementInterface
*/
private $categoryManagement;
public function __construct(
CategoryManagementInterface $categoryManagement
) {
$this->categoryManagement = $categoryManagement;
}
/**
* Fetch all Category count
*
* @return int
*/
public function getCategoryCount()
{
$categoryCount = $this->categoryManagement->getCount();
return $categoryCount;
}
}
Once you done with the code part, you can call method by using below command,
$categoryCount = $this->getCategoryCount();
That’s it.

