All-in-One Event Calendar custom template code php

I recently used All-in-One Event Calendar on a WordPress site. It’s a very rich plugin with a lot of options. Tough there is a whole theme structure behind the plug-in, real customization is a little tricky. There is that possibility to use short-codes in posts, but when I wanted to use these in WordPress templates, I got stuck. For starters there’s almost no documentation (that I know of) on functions and or queries to use for custom pages. Thus leaving me no other option that to go through the plugin code myself and figure out what to do.

Now, if you are in the same situation, I’dd like to share with you what I did.

What I want is the following: A page based on a template, displaying two sets of events both in a different event category.

All-in-One Event Calendar events are stored in WordPress as normal posts with the post-type set to ‘ai1ec_event’. For the categories it uses taxonomies. At first this looks simple enough by doing a query on the post type including (or excluding) the categories. But a bug in Worpress prevents me from doing that. The categories are ignored, because of that bug. It’s two years old and they just closed the topic and moved on without fixing it. /Sadface.

ok, now for the solution.

To get around this, I decided to take a OO approach using the events object. I did this by using the code I found here: http://pastebin.com/dxCTht6S
Then, to display the event’s I used a foreach loop (something like this):

foreach ($events as $event)
{
echo '

';
echo '

'.strftime("%A %e %B %Y",$event->start).'

';
echo '

'.$event->post->post_title.'

';
echo '

';
}

To get the categories working, I used the $filter option. I changed it to:
$filter = array('cat_ids' => array(13));

You find the categorie number if you hover above the categorie (in the post or in the editor).
http://xxx/wp-admin/edit-tags.php?action=edit&taxonomy=events_categories&tag_ID=12&post_type=ai1ec_event

If you want to display other fields of the event, you can access them in the event object. There is no map of the object, but I did a var_dump for you.

object(Ai1ec_Event)#367 (44) {
["post"]=>
object(stdClass)#329 (23) {
["ID"]=>
string(3) "832"
["post_author"]=>
string(1) "4"
["post_date"]=>
string(19) "2012-10-01 11:35:39"
["post_date_gmt"]=>
string(19) "2012-10-01 09:35:39"
["post_content"]=>
string(171) "http://xxxx"
["post_title"]=>
string(26) "World Publishing Expo 2012"
["post_excerpt"]=>
string(0) ""
["post_status"]=>
string(7) "publish"
["comment_status"]=>
string(4) "open"
["ping_status"]=>
string(4) "open"
["post_password"]=>
string(0) ""
["post_name"]=>
string(26) "world-publishing-expo-2012"
["to_ping"]=>
string(0) ""
["pinged"]=>
string(0) ""
["post_modified"]=>
string(19) "2012-10-01 11:40:30"
["post_modified_gmt"]=>
string(19) "2012-10-01 09:40:30"
["post_content_filtered"]=>
string(0) ""
["post_parent"]=>
string(1) "0"
["guid"]=>
string(92) "http://xxx/nl/?post_type=ai1ec_event&p=832&instance_id="
["menu_order"]=>
string(1) "0"
["post_type"]=>
string(11) "ai1ec_event"
["post_mime_type"]=>
string(0) ""
["comment_count"]=>
string(1) "0"
}
["post_id"]=>
string(3) "832"
["instance_id"]=>
string(1) "5"
["start"]=>
string(10) "1351465200"
["end"]=>
string(10) "1351724400"
["start_truncated"]=>
NULL
["end_truncated"]=>
NULL
["allday"]=>
string(1) "1"
["recurrence_rules"]=>
string(0) ""
["exception_rules"]=>
string(0) ""
["recurrence_dates"]=>
string(0) ""
["exception_dates"]=>
string(0) ""
["venue"]=>
string(25) "Messe Frankfurt - xxx"
["country"]=>
string(0) ""
["address"]=>
string(54) "xxx, 60327 Frankfurt/Main (Germany)"
["city"]=>
string(0) ""
["province"]=>
string(0) ""
["postal_code"]=>
string(0) ""
["show_map"]=>
string(1) "0"
["show_coordinates"]=>
NULL
["longitude"]=>
NULL
["latitude"]=>
NULL
["facebook_eid"]=>
NULL
["facebook_user"]=>
NULL
["facebook_status"]=>
NULL
["contact_name"]=>
string(0) ""
["contact_phone"]=>
string(0) ""
["contact_email"]=>
string(0) ""
["cost"]=>
string(0) ""
["ical_feed_url"]=>
string(0) ""
["ical_source_url"]=>
string(0) ""
["ical_organizer"]=>
NULL
["ical_contact"]=>
NULL
["ical_uid"]=>
string(0) ""
["tags"]=>
NULL
["categories"]=>
NULL
["feed"]=>
NULL
["category_colors":"Ai1ec_Event":private]=>
NULL
["color_style":"Ai1ec_Event":private]=>
NULL
["category_text_color":"Ai1ec_Event":private]=>
NULL
["category_bg_color":"Ai1ec_Event":private]=>
NULL
["faded_color":"Ai1ec_Event":private]=>
NULL
["tags_html":"Ai1ec_Event":private]=>
NULL
["categories_html":"Ai1ec_Event":private]=>
NULL
}

Note that some of the properties are part of the object “post”, which is in it’s part a property in the object $event, so to access them you need to use: $event->post->…

You’ll notice the $event->start is a timestamp, so you need to convert it. Use date() for this. Like so:

echo date("F j, Y, g:i a",event->start)

If you want it in your langueage, convert it using strftime() by using the locale settings. Like so:

setlocale(LC_ALL, 'nl_NL');
echo strftime("%A %e %B %Y",$event->start)

That’s about it. Have fun.
Post questions or remarks in the comment section below.

2 thoughts on “All-in-One Event Calendar custom template code php

Leave a Comment