0) { foreach ($result['values'] as $key => $api_result) { try { $additional_result = civicrm_api3('Contact', 'get', array( 'debug' => 1, 'sequential' => 1, 'contact_id' => array('=' => $api_result['id']), )); } catch (CiviCRM_API3_Exception $e) { $error = $e->getMessage(); } // If contact is not a constituent, they are already filtered. // Remove that contact from the Quick Search results. if ($additional_result['count'] == 0) { unset($result['values'][$key]); // Decrement count $result['count'] -= 1; } } } return $result; } }