1

I'm writing a WordPress plugin to display a list of CiviCRM Events, but I'm having a difficult time figuring out how to obtain the label for the event type. I can retrieve the list of events, and the event_type_id, but I haven't figured out how to retrieve the label for the event type.

    $eventList = CRM_Event_BAO_Event::getCompleteInfo();

    foreach ( $eventList as $event ) {
        // Upon further testing, the following returns a blank
        $type = CRM_Utils_Array::value( 'event_type_id', $event );

        $typeLabel = // This is where it falls apart...

    }

1 Answer 1

1

The field in the output from getCompleteInfo() is "event_type" not "event_type_id", but note that CRM_Event_BAO_Event::getCompleteInfo() is an internal function that just happens to be available, so you might prefer to use the api:

$eventList = \Civi\Api4\Event::get()->addSelect('*', 'event_type_id:label')->execute();
foreach ($eventList as $event) {
  $typeLabel = $event['event_type_id:label'];
}

It's also easier to discover what fields are available with the api, using the Support - Developer menu in civi.

1
  • Thank you for this. I was having a difficult time finding documentation, but I realize now I was looking for the wrong thing. Time to update my code! Commented Jan 30, 2023 at 12:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.