Custom display (next 7 days)

Home Forums Calendar Products Events Calendar PRO Custom display (next 7 days)

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #1093214
    Paula
    Participant

    Hi,
    I would like to construct a custom query to display 7 days (forward) worth of events. The current event-calendar-pro allows ‘week’ display which is great, however I prefer to display events in the next 7 days, also in a ‘list display’.

    I did some digging and saw there is a conditional check in /the-events-calendar/src/Tribe/Query.php line216 (version 4.0.7) Please see attached screenshot.

    code snipet 1

    How may I create this ‘custom’ display option for the backend? I can see that each display option is organised into its own folder, for customisation, one would copied the template into its correspond folder in the theme folder. How do I go about this ‘custom’ display? If you could shed some lights on these question above, that would be great. Cheers

    Ben

    #1093256
    Paula
    Participant

    Screenshot

    #1093784
    Nico
    Member

    Hi Ben,

    Thanks for reaching out! Interesting question here, I’ll help you customizing this…

    What can be done it to alter list view query to just show events for the next 7 days. Creating a new view (I’m not sure if this is your intention) is something different what would require more work and more complexity.

    Can you please confirm that altering the query for list view would be a good solution for your project?

    Thanks,
    Nico

    #1095176
    Paula
    Participant

    Hi Nico,

    ” Altering the query for list view ” sounds good. Any advice on how to do this delicately would be great. Cheers

    Regards
    Ben

    #1096070
    Nico
    Member

    Hi there Ben,

    Thanks for following up! To modify the list view query you can add this snippet to your theme’s (or child theme’s) functions.php file:


    function hijack_list_view_query ( $query ) {

    if ( tribe_is_list_view() ) {

    // uncommnet to pre-view the query args in the front end
    // echo '

    ';
    		// print_r( $query );
    		// echo '

    ';
    }

    return $query;
    }

    add_filter( 'tribe_events_pre_get_posts', 'hijack_list_view_query' );

    Just modify the params in the $query var, be sure to take a look at the WP_Query documentation!

    Hope this helps you out to get started,
    Best,
    Nico

    #1101797
    Paula
    Participant

    Hi Nico,

    Thank you for your help, really appreciated!
    I am end up using add_action instead, does what I need so far, will do more testing on this.

    Here is the code.

    
    function custom_list_view_query($query){
    
        if ( $query->tribe_is_event || $query->tribe_is_event_category ) {
            if ( ! empty( $query->query_vars['eventDisplay'] ) ) {
                switch ( $query->query_vars['eventDisplay'] ) {
                    case 'all':
                    case 'list':
                    default: // default display query
                        $event_date = ( $query->get( 'eventDate' ) != '' )
                            ? $query->get( 'eventDate' )
                            : date_i18n( Tribe__Date_Utils::DBDATETIMEFORMAT );
                        if ( ! $query->tribe_is_past ) {
                            $query->set( 'start_date', ( '' != $query->get( 'eventDate' ) ? tribe_beginning_of_day( $event_date ) : tribe_format_date( current_time( 'timestamp' ), true, 'Y-m-d H:i:s' ) ) );
                            /*
                             * customisation
                             */
                            $end_date = date( Tribe__Date_Utils::DBDATEFORMAT, strtotime( $event_date . ' +6 day' ) );
                            $myrange = Tribe__Events__Pro__Templates__Week::get_hour_range();
                            $end_date .= ' ' .  str_pad( end( array_keys( $myrange ) ), 2, '0', STR_PAD_LEFT ) . ':59:00';
                            $query->set( 'end_date', $end_date );
    
                            $query->set( 'order', Tribe__Events__Query::set_order( 'ASC', $query ) );
                        } else {
                            // on past view, set the passed date as the end date
                            $query->set( 'start_date', '' );
                            $query->set( 'end_date', tribe_end_of_day( $event_date ) );
                            $query->set( 'order', Tribe__Events__Query::set_order( 'DESC', $query ) );
                        }
                        $query->set( 'orderby', Tribe__Events__Query::set_orderby( null, $query ) );
                        $query->set( 'hide_upcoming', true );
                        break;
                }
            }
        }
        return $query;
    }
    
    add_action( 'tribe_events_pre_get_posts', 'custom_list_view_query' );
    

    Regards
    Ben

    #1102155
    Nico
    Member

    That’s great Ben! Glad you could make it work, and thanks for sharing the code here 🙂

    Is there anything else I can do for you or are we in good spot to close out the ticket?

    Best,
    Nico

    #1104071
    Paula
    Participant

    Hi Nico,
    My customisation code will cause a 404 on the event detail page. I am currently working to find a solution. Will report back here later.

    Regards
    Ben

    #1104314
    Nico
    Member

    Hey Ben,

    Thanks for the note!

    I haven’t tested the code out, but you might want to wrap the code in a view conditional:


    if ( tribe_is_list_view() ) { ... }

    Hope that helps,
    Best,
    Nico

    #1110536
    Support Droid
    Keymaster

    This topic has not been active for quite some time and will now be closed.

    If you still need assistance please simply open a new topic (linking to this one if necessary)
    and one of the team will be only too happy to help.

Viewing 10 posts - 1 through 10 (of 10 total)
  • The topic ‘Custom display (next 7 days)’ is closed to new replies.