require_once 'CRM/Core/Config.php'; $config = CRM_Core_Config::singleton(); require_once 'CRM/Contact/BAO/Contact.php'; $count = CRM_Contact_BAO_Contact::getCountComponent($config, [], [], true); echo "Total contacts: {$count}";
require_once 'CRM/Core/Config.php'; $config = CRM_Core_Config::singleton(); require_once 'CRM/Contact/BAO/Contact.php'; $count = CRM_Contact_BAO_Contact::getCountComponent($config, [], ['group' => $groupId], true); echo "Total contacts in group {$groupId}: {$count}";Here, we pass the ID of a contact group in the 'group' parameter to retrieve the number of contacts in that group. Package library: CiviCRM.