just to confirm, did you mean exclude specific event per category?
Thread Starter
pracko
(@pracko)
Yes as in all events with the category name “foo” for example.
If you are using events listing shortcode, you can try something like [events_list category=”-X”] where X is the events category id and negative ( – ) means exclude.
https://wp-events-plugin.com/documentation/shortcodes/
https://wp-events-plugin.com/documentation/event-search-attributes/
Thread Starter
pracko
(@pracko)
Angelo,
No I am NOT using a shortcode to display events in my main blog feed, I am using the following in functions.php:
/** Add Event CPT to Blog Feed **/
add_filter( 'pre_get_posts', 'my_get_posts' );
function my_get_posts( $query ) {
if ( ( is_home() && $query->is_main_query() ) || is_feed() )
$query->set( 'post_type', array( 'post', 'event' ) );
return $query;
}
Thus, I need a filter to exclude events that have a specific event category from appearing in the blog feed.
Example: When an event has passed, I change the event category from ‘active’ to ‘expired’. I need a filter so that all events assigned the category name ‘expired’ will not show in the blog feed anymore.
Thanks
this might not work out of the box, however, it should give a good start
<?PHP
$args = array(
'posts_per_page' => 3,
'post_type' => 'event',
'orderby' => 'menu_order',
'order' => 'ASC',
'tax_query' => array(
array(
'taxonomy' => 'event-categories',
'field' => 'slug',
'terms' => 'events',
),
),
);
$the_query = new WP_Query( $args );
?>
HI @pracko,
EM user here too 🙂
It would be much easier to use the shortcode, like Angelo suggested. Then you can easily use the Event Search Arguments (https://wp-events-plugin.com/documentation/event-search-attributes/)
[events_list scope="future" category="-1"]
PHP version:
do_shortcode('[events_list scope="future" category="-1"]');
“Future” will automatically hide all events with their start date before today and the negative number will exclude that Event Category ID from your list. That way you also do not need to change “active” to “expired” manually. 🙂
Hope it helps. 🙂