Display a category and exclude another in the list-widget

Home Forums Calendar Products Events Calendar PRO Display a category and exclude another in the list-widget

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #1231742
    Sébastien
    Participant

    Hi,

    I was searching for display the category of the events and I found this : https://theeventscalendar.com/support/forums/topic/display-event-category-in-upcoming-event-list-widget/

    It’s works perfectly but the code displays all of the category of my events and I want one to exclude one of them. Is there anyway to do this ? The category I want to exclude has always the same slug match-home

    It would be the point that turns perfect The Events calendar !!

    #1232803
    Barry
    Member

    Hi Sébastien,

    That’s actually a little trickier than you might imagine!

    I’d be happy to try and provide a spot of guidance but, ultimately, customizations like this are something we can’t always go into too much depth with. That said, perhaps this would provide a starting point for you (it’s a modification of the code you referenced in the other topic):

    add_action( 'tribe_events_list_widget_after_the_meta', function() {
    	$categories = tribe_get_event_categories(
    		get_the_id(), array(
    			'before'       => '',
    			'sep'          => ', ',
    			'after'        => '',
    			'label'        => null,
    			'label_before' => '<dt style="display:none;">',
    			'label_after'  => '</dt>',
    			'wrap_before'  => '<dd class="tribe-events-event-categories">',
    			'wrap_after'   => '</dd>',
    		)
    	);
    
    	$fragmented_html = explode( ',', $categories );
    
    	foreach ( $fragmented_html as $index => $fragment ) {
    		if ( false !== strpos( $fragment, '/match-home/' ) ) {
    			unset( $fragmented_html[ $index ] );
    		}
    	}
    
    	$category_html = force_balance_tags( join( ', ', $fragmented_html ) );
    	echo $category_html;
    } );

    Again, I can’t guarantee it will work for you right out of the box, but it essentially shows a simple string-based method for achieving your goals.

    I hope it helps 🙂

    #1249437
    Support Droid
    Keymaster

    Hey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.

    Thanks so much!
    The Events Calendar Support Team

Viewing 3 posts - 1 through 3 (of 3 total)
  • The topic ‘Display a category and exclude another in the list-widget’ is closed to new replies.