# Display only upcoming events in Wordpress widget

**URL:** <https://www.phphelp.com/t/display-only-upcoming-events-in-wordpress-widget/32769>\
**Category:** Code Snippets\
**Created:** [November 7, 2020, 4:11pm UTC](https://www.phphelp.com/t/display-only-upcoming-events-in-wordpress-widget/32769 "2020-11-07T16:11:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![B3000](https://www.phphelp.com/letter_avatar_proxy/v4/letter/b/e47774/32.png) [@B3000](https://www.phphelp.com/u/B3000)\
**Post date:** [November 7, 2020, 4:11pm UTC](https://www.phphelp.com/t/display-only-upcoming-events-in-wordpress-widget/32769/1 "2020-11-07T16:11:37Z")

</div>

Hi. I’d like to modify the below code to only display upcoming (younger than the current date) events from my “Custom Post Type Events” in a Wordpress widget. At the moment it shows one of all event entries randomly.

This task is beyond my limited beginners PHP knowledge.

This is the date format I am using: j. M Y

```
<h2 style="margin-bottom:10px; margin-top:5px; color:#6b6b6b; text-align:left;">Veranstaltung:</h2>
<?php
  $args = array(
    'post_type'=>'events', 
    'orderby'=>'rand', 
    'posts_per_page'=>'1'
  );

  $events=new WP_Query($args);

  while ($events->have_posts()) : $events->the_post(); 
?>
    <?php the_field('f21_event_startdate'); ?>
    <h2><a style="color:#1e73be;" href="<?php the_permalink() ?>"><?php the_title(); ?></h2>
    <div style="margin-top:10px; margin-bottom: 10px;"><?php the_post_thumbnail('full'); ?></div></a>
    <b><?php the_field('f21_event_sub_header'); ?></b>
<?php 
  endwhile;
  wp_reset_postdata();
?>
```
