Events Calendar – upcoming events widget
The Events Calendar is a powerful plugin for creating events and embedded calendar views on WordPress.
The basic version is free to download from the official WP repo: https://wordpress.org/plugins/the-events-calendar/
There are over 20 functionalities presented on its list of features, including a plethora of hooks and filters, Google Maps integration, Google Calendar and iCal exporting, saved venues and organizers, the ability to rapidly search for or create specific events, and more. It works smoothly across all platforms – desktop PCs, smartphones and tablets – and the in-depth tutorial will clear out most, if not any, potential doubts. All of this resulted in the rating of 4.4/5 stars with over 1800 submitted reviews. The developers continue to improve the tool as the popularity of the plugin is steadily growing (800,000+ active installations as of January 2021).
The plugin offers a lot of functions, but lacks displaying upcoming events. Below is a custom snippet for displaying the “Upcoming events widget” for the next 14 days. To render data, we’re using a built-in plugin shortcode [tribe:event-details]
function ctGetUpcomingEvents( $limit = '+7 days' ) { $now = date('Y-m-d'); $start_date = date('Y-m-d', strtotime($now)); $end_date = date('Y-m-d', strtotime($limit , strtotime($start_date))); // show upcoming events $args = [ 'post_type' => 'tribe_events', 'post_status' => 'publish', 'meta_query' => [ 'relation' => 'AND', 'starts_after' => [ 'key' => '_EventStartDate', 'compare' => '>', 'value' => $start_date, ], 'ends_before' => [ 'key' => '_EventStartDate', 'compare' => '<', 'value' => $end_date, ], ], 'meta_key' => '_EventStartDate', 'orderby' => 'meta_value', 'order' => 'ASC', ]; return get_posts($args); } function ctRenderUpcomingWidget(){ $events = ctGetUpcomingEvents('+14 days' ); foreach ($events as $item) { echo '<h2>'. $item->post_title . '</h2>'; echo do_shortcode('[tribe:event-details id="'. $item->ID .'"]'); } } // to render - paste into PHP template: ctRenderUpcomingWidget();