$contactId = 123; $contact = CRM_Contact_BAO_Contact::retrieve($contactId); $subType = CRM_Contact_BAO_Contact::getContactSubType($contact); echo "The contact subtype is: " . $subType;
$contactIds = [456, 789, 012]; $subTypes = []; foreach ($contactIds as $contactId) { $contact = CRM_Contact_BAO_Contact::retrieve($contactId); $subTypes[] = CRM_Contact_BAO_Contact::getContactSubType($contact); } print_r($subTypes);In this example, we have an array of contact IDs and we want to retrieve the subtypes of all these contacts. We loop through each contact, retrieve it using the retrieve function and then pass it to the getContactSubType function. We then add the subtype to an array. Finally, we print out the array of subtypes using the print_r function. Package library: CiviCRM.