How to create a Simple Events System with Easy Content Types

Event calendars are pretty complex and difficult systems to build. There are lots of plugins that provide a range of functionality, everything from really, really simple events management, to full blow event calendar layouts, ticket purchased and more. A lot of people, however, are very unsatisfied with the available options, either because they are too complex or don’t fit in with the site’s design. So I’m going to show you how to create a simple events system that can fit in perfectly with your site, no matter what theme you use.

The video above walks you through the entire process. It’s actually pretty simple. Because of the nature of this tutorial, I’m not going to go step by step through the code in the text part (it’s all covered in the tutorial), but I am including all of the necessary code for the events query.

The final code used in my page template is below:

  <h3>Upcoming Events</h3>
<?php
	$upcoming_args = array(
		'post_type' => 'events',
		'orderby' => 'meta_value',
		'order' => 'ASC',
		'posts_per_page' => -1,
		'meta_key' => 'ecpt_date',
		'meta_value' => time(),
		'meta_compare' => '>='
	);
	$upcoming_events = get_posts($upcoming_args);
	if($upcoming_events) {
		echo '<ul>';
		foreach($upcoming_events as $event) {
			$time = get_post_meta($event->ID, 'ecpt_event_time', true);
			$date = get_post_meta($event->ID, 'ecpt_date', true);
			$date = date('F j, Y', $date);
			echo '<li>';
				echo '<a href="' . get_permalink($event->ID) . '">' . get_the_title($event->ID) . '</a><br/>';
				echo 'Date: ' . $date . ' - Time: ' . $time;
			echo '</li>';
		}
		echo '</ul>';
	}
?>
 
<h3>Past Events</h3>
<?php
	$past_args = array(
		'post_type' => 'events',
		'orderby' => 'meta_value',
		'order' => 'DESC',
		'posts_per_page' => -1,
		'meta_key' => 'ecpt_date',
		'meta_value' => time(),
		'meta_compare' => '<'
	);
	$past_events = get_posts($past_args);
	if($past_events) {
		echo '<ul>';
		foreach($past_events as $event) {
			$time = get_post_meta($event->ID, 'ecpt_event_time', true);
			$date = get_post_meta($event->ID, 'ecpt_date', true);
			$date = date('F j, Y', $date);
			echo '<li>';
				echo '<a href="' . get_permalink($event->ID) . '">' . get_the_title($event->ID) . '</a><br/>';
				echo 'Date: ' . $date . ' - Time: ' . $time;
			echo '</li>';
		}
		echo '</ul>';
	}
?>