Ask your WordPress questions! Pay money and get answers fast! (more info)

Exclude one event category from main post loop

  • SOLVED

Hi

[Plugin: The Event Calendar]
[Theme: Vantage]

I'm using The Event Calendar plugin. I've created two categories (HIDDEN and NEWS) within it.
All events are added to my main blog-loop, but I don't want the HIDDEN category to show up.

How do I do this?

Best regards,
<em>MadsRH</em>

Answers (2)

2016-08-14

Hariprasad answers:

Hello MadsRH,

Try this on your functions.php,
add_action( 'pre_get_posts', 'home_exclude_events_category' );
function home_exclude_events_category( $query ) {
if ( $query->is_home() && $query->is_main_query() ) {
$query->set( 'tax_query', array(
array(
'taxonomy' => TribeEvents::TAXONOMY,
'field' => 'slug',
'terms' => array( 'hidden'),
'operator' => 'NOT IN'
)
) );
}

return $query;
}

Regards,
Hariprasad


Mads R.H. comments:

Hariprasad -> Perfect! Thank you!

Can I use the same category name (hidden) for my regular posts, if I would want to hide one of them too?

2016-08-14

Navjot Singh answers:

You can try something like this: [[LINK href="https://gist.github.com/geoffgraham/247cf5d7c7e618a60db9"]]https://gist.github.com/geoffgraham/247cf5d7c7e618a60db9[[/LINK]]


Mads R.H. comments:

Navjot Singh -> This removes the categories from the widget, but not from the blog-loop