Support » Plugin: Events Manager » Show custom taxonomy ‘Band’ in frontend – Events Manager

  • Resolved wenkunst

    (@wenkunst)


    I’m using a custom taxonomy ‘Bands’ with Events Manager.

    As mentioned in the tutorial (https://wp-events-plugin.com/tutorials/using-additional-custom-taxonomies/) I used:

    function my_em_own_taxonomy_register(){
        register_taxonomy_for_object_type('bands',EM_POST_TYPE_EVENT);
        register_taxonomy_for_object_type('bands',EM_POST_TYPE_LOCATION);
        register_taxonomy_for_object_type('bands','event-recurring');
    }
    add_action('init','my_em_own_taxonomy_register',100);
    

    I want to use the placeholder #_BANDS to show which bands are playing at an event.

    This tutorial (https://wp-events-plugin.com/tutorials/create-a-custom-placeholder-for-event-formatting/) shows how to make a custom placeholder.

    But, how do I get the custom taxonomy out of the EM_EVENT object? Displaying $EM_Event doesn’t show any ‘bands’ taxonomy.

    This is the example, here the taxonomy ‘STYLES’ is used:

    add_filter('em_event_output_placeholder','my_em_styles_placeholders',1,3);
    function my_em_styles_placeholders($replace, $EM_Event, $result){
        if( $result == '#_STYLES' ){
            $replace = 'none';
            if( count($EM_Event->styles) > 0 ){
                $my_em_styles = (is_array(get_option('my_em_styles'))) ? get_option('my_em_styles'):array();
                $styles = array();
                foreach( $EM_Event->styles as $id ){
                    if( !empty($my_em_styles[$id]) ){
                        $styles[] = $my_em_styles[$id];
                    }
                }
                $replace = implode(', ', $styles);
            }
        }
        return $replace;
    }

    Am I missing something? 🙂

    I’m using version 5.9.5 of the Event Manager with WordPress 4.9.8

Viewing 5 replies - 1 through 5 (of 5 total)
  • Your bands are not stored as an option in the database and that is what the second code looks for (get_option()).

    To fetch taxonomies from an object your need to use wp_get_object_terms().

    https://developer.wordpress.org/reference/functions/wp_get_object_terms/

    Thanx Patrick, that works of course! I should have tried that earlier… 🙂

    Yes, the styles example did not use a custom taxonomy, so it is quite different. But on the backend site, does it work already that you can define the bands for an event? If so and they are saving, there is surely a way to pull them out there. But the code will be quite different.

    @wenkunst: So what did you add now to your functions.php that is in addition to the “styles” example? I had a similar problem and couldn’t solve it. Your working code would be very helpful for me.
    Thanks in advance!
    Kathrin

    @pferdetermine: This is what I’m using now:

    add_filter('em_event_output_placeholder','my_em_styles_placeholders',1,3);
    function my_em_styles_placeholders($replace, $EM_Event, $result){
        if( $result == '#_BANDS' ){
            $replace = 'none';
            
            $terms = get_the_terms( $EM_Event->post_id, 'bands' );
            
            if( count($terms) > 0 ){
    
                foreach( $terms as $term ){
                    if( !empty($term->name) ){
                        $bands[] = $term->name;
                    }
                }
                $replace = implode(', ', $bands);
            }
        }
        return $replace;
    }
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Show custom taxonomy ‘Band’ in frontend – Events Manager’ is closed to new replies.