Create Your Own RSVPMaker Events Listing Format

I’ve been working on creating a better API for developers who want to extend RSVPMaker, without hacking the core code of the plugin or overriding the pluggable functions. This example shows how you might take advantage of the get_future_events() function to write your own shortcode or widget code that outputs an event listing in a format of your own design.

get_future_events accepts 2 parameters, both optional — get_future_events($where,$limit)

$where is a SQL clause like ‘post_author=2’

$limit is a limit on the number of events that should be returned.

In this example, I added a shortcode that accepts where and limit as parameters that can be passed to the get_future_events function. You can also use before and after with either a specific MySQL formatted date or a date function like CURDATE() or DATE_ADD(). The past attribute directs RSVPMaker to use the get_past_events() function (which works the same way) instead. (This was only supposed to be a simple example, but I got carried away.)

I also included a showfield attribute to let you see the fields returned (the post_content body is hidden). In addition to all the normal $post properties, you get datetime (the full MySQL datetime for the event) and date (a formatted version). You can output the date in a different format by running the datetime data through PHP’s strtotime() to get a timestamp and then formatting your date with date() or strftime().

Here is the code, followed by a couple of examples.

add_shortcode('rsvpmaker_shortcode_demo','rsvpmaker_shortcode_demo');

function rsvpmaker_shortcode_demo ($atts) {
$output = '';
$where = (isset($atts["where"])) ? $atts["where"] : '';
$limit = (isset($atts["limit"])) ? $atts["limit"] : 5;
if(isset($atts["after"]))
	{
		if(!empty($where))
			$where .= ' AND ';
		if(strpos($atts["after"],'-')) // if this looks like a mysql date
			$where .= "datetime > '".$atts["after"]."'";
		else // if this looks like a relative code like NOW() or DATE_ADD
			$where .= "datetime > ".$atts["after"];		
	}
if(isset($atts["before"]))
	{
		if(!empty($where))
			$where .= ' AND ';
		if(strpos($atts["after"],'-')) // if this looks like a mysql date
			$where .= "datetime < '".$atts["after"]."'";
		else // if this looks like a relative code like NOW() or DATE_ADD
			$where .= "datetime < ".$atts["after"];		
	}
$events = get_future_events($where,$limit);
if(isset($atts["showfields"]))
{
	$showdata = $events[0];
	$showdata->post_content = '[post content goes here]';
	return '<blockquote>'.var_export($showdata,true).'</blockquote>';
}	
foreach($events as $index => $event)
	{
		$style = ($index && ($index % 2)) ? 'background-color: #fee; padding: 10px;' : 'background-color: #eef; ; padding: 10px;';
		$output .= sprintf('<p style="%s">%s<br /><a href="%s">%s</a></p>',$style,$event->date,get_permalink($event->ID),$event->post_title);
	}
return $output;
}

[rsvpmaker_shortcode_demo]
Output:

[rsvpmaker_shortcode_demo]

[rsvpmaker_shortcode_demo showfields="1"]
Output:

[rsvpmaker_shortcode_demo showfields=”1″]

[rsvpmaker_shortcode_demo where="post_title LIKE ‘%the%’"]
Output:

[rsvpmaker_shortcode_demo where=”post_title LIKE ‘%the%'”]

[rsvpmaker_shortcode_demo after="DATE_ADD(NOW(), INTERVAL 30 DAY)"]
Output:

[rsvpmaker_shortcode_demo after=”DATE_ADD(NOW(), INTERVAL 30 DAY)”]

[rsvpmaker_shortcode_demo past="1"]
Output:
[rsvpmaker_shortcode_demo past=”1″]

2 thoughts on “Create Your Own RSVPMaker Events Listing Format”

  1. There is a mechanism documented here http://www.rsvpmaker.com/2010/12/changing-the-rsvp-form-other-customizations/ for adding custom code with a rsvpmaker-custom.php file, uploaded into the main plugins directory (above the rsvpmaker folder). RSVPMaker checks to see if a file with that name exists, and loads it if it’s present.

    Alternately, you could add the code to your theme’s functions.php (if it’s a custom theme or a child theme that won’t get overwritten by updates) or to a small plugin of your own design.

Leave a Reply