Display category next to Title

This topic contains 5 replies, has 2 voices, and was last updated by  Stephen Harris 9 years, 9 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #17173

    Hello Stephen,

    Two—kind of—related questions

    1 – Is there a way to display the category of an event inside the tooltips that come with the event_map shortcode?

    2 – What about showing the category in the full calendar view (eo_fullcalendar), next to each event title or, alternatively, inside the tooltip of each event?

    I searched here http://docs.wp-event-organiser.com/shortcodes/events-map/ for 1;
    and here http://codex.wp-event-organiser.com/hook-eventorganiser_event_tooltip.html for 2, but I still don’t know how to get the category in either case.

    I’ll also take the opportunity to thank you for the great support!!

    Duarte Lourenco
    #17175

    Hi Duarte,

    Yes, both are possible. You’ve found the correct link for (2), just be aware that changes will only take effect one the cache is cleared (i.e. an event is updated). Here’s how to get the event categories in that case

    add_filter( 'eventorganiser_event_tooltip', 'my_callback_function', 10, 4 );
    function my_callback_function( $description, $event_id, $occurrence_id, $post ){
    
        //Gets an array of event categories for this event
        $categories = get_the_terms( $event_id, 'event-category' );
    
        //Change first value and return it
        return $description;
    
    };
    

    $categories in the above is an array of term objects. And you can get the name from a term object with:

    $term->name;
    

    See the examples on this page for more details: https://codex.wordpress.org/Function_Reference/get_the_terms

    Something similar can be done for the event map, but note that the context is the venue not an event. As such you have potentially multiple events, so you would need to loop through them:

    function my_change_event_map_tooltip( $tooltip_content, $venue_id, $events ){
         foreach( $events as $event ){
               $categories = get_the_terms( $event->ID, 'event-category' );
         }
         return $tooltip_content;
    }
    add_filter( 'eventorganiser_event_map_tooltip', 'my_change_event_map_tooltip', 10, 3 );
    
    Stephen Harris
    #17185

    Stephen,

    I’m sorry, but I failed to make it work. I couldn’t apply those examples to our case, as everything I tried returned the dreaded blank page or didn’t do anything…

    Can I ask you for more details on how to return the category name on that first example of yours?

    Ty

    Duarte Lourenco
    #17207

    Here’s an example:

    add_filter( 'eventorganiser_event_tooltip', 'my_callback_function', 10, 4 );
    function my_callback_function( $description, $event_id, $occurrence_id, $post ){
    
        $description .= get_the_term_list( 
            $event_id, 
            'event-category',
            '<p> This event is categorised: ' , 
            ', ', 
            '</p>' 
        );     
    
        return $description;
    
    };
    

    I’ve used get_the_term_list() as it creates a nice list of categories (with links) automatically.

    Stephen Harris
    #17273

    Hello Sephen

    Thank you.

    And what if I want to have the categories next to the title of the event, on the calendar view? (not in the tooltip)

    Taking the demo page, http://wp-event-organiser.com/demo/calendar/ , imagine a category name displaying right next to “Fortnightly event”

    Duarte Lourenco
    #17285

    You can use the eventorganiser_fullcalendar_event hook for that. As above, please note that the calendar is cached.

    add_filter( 'eventorganiser_fullcalendar_event', 'my_fc_callback_function', 10, 3 );
    function my_fc_callback_function( $event, $event_id, $occurrence_id ){
    
        $terms = get_the_term_list( 
            $event_id, 
            'event-category',
            ' (' , 
            ', ', 
            ')' 
        );     
    
        $event['title'] .= strip_tags( $terms );
    
        return $event;
    
    };
    
    Stephen Harris
Viewing 6 posts - 1 through 6 (of 6 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.