get_cat_name equivalent

Home Forums Calendar Products Events Calendar PRO get_cat_name equivalent

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #988555
    Kent Rygiel
    Participant

    I am going nuts here as I can’t figure out the answer to this seemingly simple question.

    How do I get the category name/slug/term of an event using the category ID? I am looking for the equivalent of: get_cat_name().

    So, I know that the ID is 8, and I am trying to echo the Category name (“Webinar”) using this ID. Something like : get_cat_name(8).

    Does anyone have thoughts? If so, they would be MUCH appreciated.

    Thanks,
    Kent

    #988685
    Barry
    Member

    Hi Kent,

    You might use WordPress’s get_term_by() function:

    $id   = 8; // whatever you believe the term ID to be
    $term = get_term_by( 'id', $id, Tribe__Events__Main::TAXONOMY );
    
    // Test to see if you got an expected result before trying to display
    if ( false !== $term ) echo $term->name;

    Of course you could wrap this up in a function of your own for easier re-use 🙂

    #988725
    Kent Rygiel
    Participant

    Boom. That worked like a charm. Thank you so much for the help.

    #988820
    Barry
    Member

    My pleasure 🙂

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘get_cat_name equivalent’ is closed to new replies.