Hi,
Is it possible to allow a site visitor to switch group occurrences on and off via a checkbox or button? This would be on event-archive.php, not a widget or shortcode.

Winston Grace
Hi Winston,
No, at least not out of the box. Using pre_get_posts you could call
$query->set('group_events_by','series');
// or
$query->set('group_events_by','occurrence');
as required – you’d need to make sure you are targeting the right query. You’d also need to store the user’s preference – maybe a a cookie or in the database – and retrieve that to decide which to call.

Stephen Harris
I realise this is a very old thread, but I want to thank you for the suggestion. It got me thinking, and I’m using a URL parameter to switch between the two:
function prefix_custom_query_vars_filter( $vars ) {
$vars[] = 'hide';
return $vars;
}
add_filter( 'query_vars', 'prefix_custom_query_vars_filter');
function prefix_events_archives( $query ) {
if ( is_admin() ) {
return;
}
if ( $query->is_main_query() && ( is_post_type_archive( 'event' ) ) ) {
$hide = get_query_var( 'hide' );
if ( $hide === 'recurring' ) {
$query->set( 'group_events_by', 'series' );
}
}
}
add_action( 'pre_get_posts', 'prefix_events_archives' );

Winston Grace