Tribes The Events Calendar: Display event categories and get ACF custom fields

PHOTO EMBED

Tue Nov 09 2021 18:30:40 GMT+0000 (Coordinated Universal Time)

Saved by @markf_raindrop #php

<? $event_cats_args = array(
            'orderby' => 'name',
            'order' => 'ASC',
            'fields' => 'all'
        ); 
$event_cats = wp_get_object_terms( $event_id, array( 'tribe_events_cat' ), $event_cats_args );
if ( empty( $event_cats ) ) {
  return;
}
if ( is_wp_error( $event_cats ) || ! is_array( $event_cats ) ) {
  return;
} ?>
  
<div class="event-categories">
    <? foreach( $event_cats as $cat ) { 
    	$catid = $cat->term_id;
    	$catname = $cat->name;
    	$catslug = $cat->slug;
    	$catcolor = get_field('category_color', 'tribe_events_cat_' . $catid);
    ?>
      
      <a href="/events/category/<?= $catslug; ?>" rel="tag" style="background-color: <?= $catcolor; ?>;"><?= esc_html( $catname ); ?></a>

    <? } ?>
</div>
content_copyCOPY