Support » Plugin: Events Manager » [Plugin: Events Manager] #_CATEGORYLINK to diplay top level category of an event

  • Resolved raskull


    I have event categories, and subcategories. Each event has its parent category, and a subcategory.

    When I use #_CATEGORYLINK I get, from among the event’s categories and subcategories, the name with the highest alphabetical ranking.

    So an event categorized

     - Apples

    will display the category as Apples, not Fruit.

    Whereas an event categorized

     - Macintosh

    will display the category as Apples.

    How can I return only the parent category?

Viewing 15 replies - 1 through 15 (of 15 total)
  • have you tried template file templates/placeholders/categories.php –


    Here’s what I want to do. Create a placeholder called #_CATEGORYPARENTLINK

    I can do that. Now I need to know the syntax to display category depth=1 (parent) for an event.

    It would work exactly the same as #_CATEGORYLINK but it would exclude child categories.

    you can try this snippet or modify –

    (paste in your theme functions.php)

    Hm… that’s a start — it creates the placeholder #_CATEGORYPARENTLINK, but that’s about it. Let me see if I can rephrase what I am looking for…

    For each event, get its parent category

    okay, if you are successful on rephrasing you might want to share it to the community.

    I am stuck on this one. I don’t see where the code decides which category to show, of all the categories and subcategories an event might belong to. Show me how to echo an event’s categories and subcategories and maybe I can make some headway….

    the snippet should get the parent category of the event? also, you can use print_r($EM_Category); or see this link

    No, the snippet does not produce anything. $replace remains at ” after line 7. I’ve read the placeholder tutorial a million times, I got that part.

    Plugin Author Marcus


    NetWebLogic Support

    you can just use get_terms as well –

    Since all you need is $EM_Event->post_id. Then the parent should be in that returned object.

    ok… I got something working. Your snippet returns a parent of a child, but returns nothing if it is not a child (i.e. a parent). So I changed line 7 to
    $replace = '<a href="' . get_term_link( $EM_Category->name, EM_TAXONOMY_CATEGORY ) . '">' . $EM_Category->name . '</a>';

    That seems to work. But is the snippet the most efficient way to do this? I was trying to do something like:

    if ( $this->parent == 0 ) $replace = $this->name;
    else $replace = $this->parent [but turn id into name]

    But I can’t figure out the syntax. Either way, thanks!


    edited the snippet at

    I changed your line 12 to
    if ( ( count( $child ) >= 0 ) && ( $EM_Category->name == $arrterm->name ) ) {
    and got rid of the redundant else if. Works great. Thanks so much!

    …and so it doesn’t choke if an event has no parent category associated with it, wrap with a conditional:

    $replace = '';
    	if ( $EM_Category->name ) {

    Also modified your lines 13 and 20.

    get_term_link( $EM_Category->name, EM_TAXONOMY_CATEGORY )
    get_term_link( $arrterm->name, EM_TAXONOMY_CATEGORY )


    get_term_link( $EM_Category->slug, EM_TAXONOMY_CATEGORY )
    get_term_link( $arrterm->slug, EM_TAXONOMY_CATEGORY )

    Plugin Author Marcus


    NetWebLogic Support

    I’d suggest you post your modified version to, to avoid any typos. thanks!

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘[Plugin: Events Manager] #_CATEGORYLINK to diplay top level category of an event’ is closed to new replies.