Dashboard Widget: Events in the Next Two Weeks
Adds a dashboard widget listing the events coming up in the next 14 days with dates and quick edit links, so the team always knows what is on.
Opens WPIDE on
Code
$wpide_days = 14; // Days ahead to show.
add_action( 'wp_dashboard_setup', function () use ( $wpide_days ) {
if ( ! function_exists( 'tribe_get_events' ) || ! current_user_can( 'edit_posts' ) ) {
return;
}
wp_add_dashboard_widget( 'wpide_tec_next', __( 'Coming up' ), function () use ( $wpide_days ) {
$events = tribe_get_events( array(
'start_date' => 'now',
'end_date' => wp_date( 'Y-m-d 23:59:59', time() + $wpide_days * DAY_IN_SECONDS ),
'posts_per_page' => 15,
) );
if ( ! $events ) {
echo '<p>' . esc_html__( 'Nothing scheduled.' ) . '</p>';
return;
}
echo '<ul>';
foreach ( $events as $event ) {
printf(
'<li><strong>%1$s</strong> – <a href="%2$s">%3$s</a></li>',
esc_html( tribe_get_start_date( $event, true, 'D j M, H:i' ) ),
esc_url( (string) get_edit_post_link( $event->ID ) ),
esc_html( get_the_title( $event ) )
);
}
echo '</ul>';
} );
} );
Notes
Change $wpide_days to look further ahead.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.