Display category description

This topic contains 4 replies, has 2 voices, and was last updated by  Johannes Buchner 6 years, 8 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #28186

    Hi Stephen,
    I’d like to display the category description in the single-event template.
    I’ve gotten pretty far using category_description() however I don’t know how to get the category id.

    $category_id = what do I put here???;<br>
    echo category_description( $category_id );

    Can you please help me out with the right code?
    Thanks!

    Johannes Buchner
    #28188

    Hi Johannes,

    Events can have multiple categories, so in the following I’m assuming you’re only interested in the ‘first’ one:

    $terms = get_the_terms( get_the_ID(), 'event-category' );
    $term = array_shift( $terms );
    $term_id = (int) $term->id;
    echo term_description( $term_id, 'event-category' );
    

    You have to use term_description as category_description is for post categories.

    Stephen Harris
    #28189

    Thank you for your fast respond, Stephen!

    You’re right, I only want to display the first category description.
    Unfortunately the code isn’t working on my site yet. It is not showing any description.

    When I replace $term_id with a specific id number the result is exactly what I want.
    So there seems to be a problem with the paremeter “$term_id”.

    Any ideas?

    Johannes Buchner
    #28196

    Sorry, try

    $term_id = (int) $term->term_id;
    
    Stephen Harris
    #28197

    Thanks Stephen,

    that did the trick

    Johannes Buchner
Viewing 5 posts - 1 through 5 (of 5 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.