Allow user to group occurrences on front end

WordPress Event Management, Calendars & Registration Forums General Question Allow user to group occurrences on front end

This topic contains 2 replies, has 2 voices, and was last updated by  Winston Grace 3 years, 3 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #38315

    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
    #38366

    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
    #40200

    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
Viewing 3 posts - 1 through 3 (of 3 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.