Support

Home Forums Event Espresso Premium Adding category to event lists in EE4

Adding category to event lists in EE4

Posted: October 8, 2016 at 11:45 am

Viewing 4 reply threads


Stephen Lavallee

October 8, 2016 at 11:45 am

Hi- I’m trying to add event category names to display in the event lists on my site. I’m editing content-espresso_events-header.php to add the category directly following the event title. I have tried various methods at this point, and either I am returned nothing, or ‘array’. The code below returns ‘array’. Where am I going wrong? Thanks.


<?php
//echo '<br/><h6 style="color:#2EA2CC;">'. __FILE__ . '   <span style="font-weight:normal;color:#E76700"> Line #: ' . __LINE__ . '</span></h6>';
global $post;
?>
<header class="event-header">
<?php if ( is_single() ) : ?>
<h1 id="event-details-h1-<?php echo $post->ID; ?>" class="entry-title">
<?php else : ?>
<h2 id="event-details-h2-<?php echo $post->ID; ?>" class="entry-title">
<?php endif; ?>
"><?php the_title(); ?><br /><?php $category = get_the_category(); echo $category; ?>
<?php if ( is_single() ) : ?></h1><?php else : ?></h2><?php endif; ?>
<?php if ( ! is_archive() && has_excerpt( $post->ID )): the_excerpt(); endif;?>
</header>


Stephen Lavallee

October 8, 2016 at 11:47 am

To clarify, line 11 is the code in question…
<a class="" href="<?php the_permalink(); ?>"><?php the_title(); ?><br /><?php $category = get_the_category(); echo $category; ?></a>


Josh

  • Support Staff

October 10, 2016 at 11:53 am

Hi Stephen,

In the code in question, you’re using the get_the_category() function. That function only returns results from the default “category” taxonomy. Event Espresso event categories are a custom taxonomy. You can use get_the_terms() for custom taxonomies. See also:

https://developer.wordpress.org/reference/functions/get_the_category/

https://developer.wordpress.org/reference/functions/get_the_terms/

https://eventespresso.com/wiki/ee4-custom-post-types/#taxonomies


Stephen Lavallee

October 10, 2016 at 12:01 pm

Thanks Josh- I actually JUST NOW figured out how I need to do this by using your answer at:

https://eventespresso.com/topic/ee4-show-event-category-wo-link-and-check-if-event-is-in-a-specific-category/

Took me a while to locate the espresso_event_categories() function.

Thanks.


Josh

  • Support Staff

October 10, 2016 at 12:14 pm

That’s another way to accomplish the same thing.

Viewing 4 reply threads

The support post ‘Adding category to event lists in EE4’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso