tribe_has_next_event()
Are there any events next (in the future) to the current events in $wp_query
Return
(bool)
Source
File: src/functions/template-tags/loop.php
function tribe_has_next_event() {
$wp_query = tribe_get_global_query_object();
$has_next = false;
if ( null === $wp_query ) {
return apply_filters( 'tribe_has_next_event', $has_next );
}
$past = tribe_is_past();
$upcoming = ! $past;
$cur_page = (int) $wp_query->get( 'paged' );
$max_pages = (int) $wp_query->max_num_pages;
$page_1 = 0 === $cur_page || 1 === $cur_page;
// if we are on page "0" or 1, consider it page 1. Otherwise, consider it the current page. This
// is used for determining which navigation items to show
$effective_page = $page_1 ? 1 : $cur_page;
// Simple tests based on pagination properties
if ( $upcoming && $effective_page < $max_pages ) $has_next = true;
if ( $past && $effective_page > 1 ) $has_next = true;
// Test for future events (on first page of the past events list only)
if ( $past && $page_1 && ! $has_next ) {
// Inherit args from the main query so that taxonomy conditions etc are respected
$args = (array) $wp_query->query;
// Make some efficiency savings
$args['no_paging'] = true;
$args['no_found_rows'] = true;
$args['posts_per_page'] = 1;
/**
* Filters the arguments that will be used to check if there is a next page/event.
*
* @since 4.9
*
* @param array $args An array of arguments that will be used to check if a next page/event
* is present.
* @param WP_Query $wp_query The query object the query arguments have been taken from.
*/
$args = apply_filters( 'tribe_events_has_next_args', $args, $wp_query );
$next_event = tribe_get_events( $args );
$has_next = ( count( $next_event ) >= 1 );
}
return apply_filters( 'tribe_has_next_event', $has_next );
}