Support

Home Forums Event Espresso Premium Filter events by tags instead of category

Filter events by tags instead of category

Posted: August 19, 2016 at 8:31 am


yamamDev

August 19, 2016 at 8:31 am

Hello,

Im looking to filter my events using the tag taxonomy instead of categories in the table view. Im using the category taxonomy to show different lists of events on different pages. I see there is a currently a way to filter the events by category that utilizes the function/argument espresso_event_categories to grab all categories. Im wondering if there is a similar function that grabs all tags.

Alternatively, if there is a better/different way to create separate event lists and use shortcodes to display them.

Thanks!


Josh

  • Support Staff

August 19, 2016 at 2:03 pm

Hi there,

WordPress includes a tag archive. Here’s a link to some documentation:

https://codex.wordpress.org/Tag_Templates

So how that works in EE4 is when you tag some events with the same tag, they’ll all appear in that tag’s archive, which will have this URL structure:

http://yoursite.com/tag/tagslug

One thing to keep in mind though: If you have events and regular WP posts that are given the same tag, they’ll both appear in the same tag archive.


yamamDev

August 19, 2016 at 2:31 pm

Right, which is why I was wondering if theres a way to pull only the event tags. But it seems like the tags are batched in with all of wordpress.

But I did manage to work out a way to grab some of the event tags, but just not sure how to get them all in one array rather than printing out per post.

Im using the table-template add-on, and in the loop there was a conditional that grabbed the category of each post and printed it onto the wrapper class:

while ( have_posts() ) : the_post();
    global $post;
    
    $event = EEH_Event_View::get_event();
    if ( $event instanceof EE_Event ) {
	if ( $event_categories = get_the_terms( $event->ID(), 'espresso_event_categories' )) {
	    // loop thru terms and create links
	    $category_slugs = '';
	    foreach ( $event_categories as $term ) {
		$category_slugs[] = $term->slug;
	    }
	    $category_slugs = implode(' ', $category_slugs);
	} else {
	    // event has no terms
	    $category_slugs = '';
	}
}

And i modified that to grab the events tags:

if ( $event_tags = get_the_tags( $event->ID() )) {
	// loop thru terms and create links
	$tag_slugs = '';
	foreach ( $event_tags as $term ) {
		$tag_slugs[] = $term->slug;
	}
	$tag_slugs = implode(' ', $tag_slugs);
} else {
	// event has no terms
	$tag_slugs = '';
}

is there a similar method that would let me get ALL the tags that the events are using into an array? Im trying to print out checkboxes and filter via tag values.


Josh

  • Support Staff

August 19, 2016 at 2:57 pm

https://codex.wordpress.org/Function_Reference/get_tags

The support post ‘Filter events by tags instead of category’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Support forum for Event Espresso 3 and Event Espresso 4.
Documentation for EE3 and EE4
Documentation for Event Espresso 3

Documentation for Event Espresso 4

Status: closed

Updated by  Josh 3 years, 1 month ago ago

Topic Tags

Notifications

This topic is: not resolved
Do NOT follow this link or you will be banned from the site!