Update to the previously posted code.
I’ve noticed an error. I shouldn’t have assumed that all $query objects have a ‘post_type’ component. I’ve updated the code as follows and would still appreciate any help with excluding the past events.
/* Filter The Events */
function events_filter($query) {
if ( !is_admin() && $query->is_main_query() ) {
if( $query->is_archive && isset($query->query['post_type']) ) {
if( $query->query['post_type'] == 'events' ) {
$query->set('posts_per_page', -1);
$query->set('order', 'asc');
$query->set('meta_key', 'start_date');
$query->set('orderby', 'meta_value_num');
/* Code to exclude past events needed here. */
}
}
}
}
add_action('pre_get_posts','events_filter');