Display just category name

Home Forums Calendar Products Events Calendar PRO Display just category name

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #1138523
    David
    Participant

    Hi there,

    This may have been answered already but if so, I can’t find it.

    I’m doing some custom theming and am looking to display the category name on a page (in this case, “Training”)

    I was able to use the following to output the venue and the time, and they worked fine:

    Then I tried to use this to out put the event’s category:

    And it echoes back:

    Event Category:

    How do I just get it to echo back the word “Training” and nothing else (without any of the div, ul, li, a or any other tags) like the venue and address above do? I just need the event category name to display, no html tags at all.

    Thanks for any help.

    #1138923
    Nico
    Member

    Hey David,

    Glad to help you out with this issue as well!

    Let me start by saying that sp_get_venue is deprecated and should use tribe_get_venue instead. Also use tribe_get_address instead of sp_get_address. Regarding the categories in text format you can add the snippet below to your theme’s (or child theme’s) functions.php file:


    if ( class_exists('Tribe__Events__Main') ){

    /* get event category names in text format */
    function tribe_get_text_categories ( $event_id = null ) {

    if ( is_null( $event_id ) ) {
    $event_id = get_the_ID();
    }

    $event_cats = '';

    $term_list = wp_get_post_terms( $event_id, Tribe__Events__Main::TAXONOMY );

    foreach( $term_list as $term_single ) {
    $event_cats .= $term_single->name . ', ';
    }

    return rtrim($event_cats, ', ');

    }

    }

    Once the code is in place you can call the function in the template: echo tribe_get_text_categories ();.

    Please give a try and let me know if it works for you,
    Best,
    Nico

    #1139331
    David
    Participant

    Works perfect, just what I was looking for. Thanks Nico.

    #1139332
    Nico
    Member

    Stocked to hear David, thanks for the heads-up 🙂

    I’ll go ahead and close out this thread, but if you need help with anything else please don’t hesitate to create a new one and we will be happy to assist you.

    Best,
    Nico

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Display just category name’ is closed to new replies.