Home › Forums › Calendar Products › Events Calendar PRO › Custom display (next 7 days)
- This topic has 9 replies, 3 voices, and was last updated 8 years ago by Support Droid.
-
AuthorPosts
-
March 23, 2016 at 4:59 pm #1093214PaulaParticipant
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.
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
March 23, 2016 at 9:06 pm #1093256PaulaParticipantScreenshot
March 24, 2016 at 5:23 pm #1093784NicoMemberHi 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,
NicoMarch 28, 2016 at 8:35 pm #1095176PaulaParticipantHi Nico,
” Altering the query for list view ” sounds good. Any advice on how to do this delicately would be great. Cheers
Regards
BenMarch 30, 2016 at 12:31 pm #1096070NicoMemberHi 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,
NicoApril 13, 2016 at 12:00 am #1101797PaulaParticipantHi 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
BenApril 13, 2016 at 2:25 pm #1102155NicoMemberThat’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,
NicoApril 18, 2016 at 9:46 pm #1104071PaulaParticipantHi 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
BenApril 19, 2016 at 9:01 am #1104314NicoMemberHey 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,
NicoMay 4, 2016 at 9:35 am #1110536Support DroidKeymasterThis 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. -
AuthorPosts
- The topic ‘Custom display (next 7 days)’ is closed to new replies.