Export Custom Post Type Events to iCal (.ics) Calendar Format

Creating events in WordPress has become second nature to us. But it wouldn’t have been so clear were it not for the incredible brain of Noel Tock. He wrote a tremendous tutorial series covering creating a calendar system that is actually usable by clients. Best of all, it doesn’t suffer from the bloat we typically see in other event calendar wordpress plugins.

Getting WordPress To Jive with CPT Events and exported into iCal

If you’re new to creating events via custom post types, Noel Tock’s series is well worth the read. He breaks down each section bit by bit. The sheer amount of other developers chiming in within the comments is enough to shed a tear.

Part 1 – Custom Post Types Events

Part 2 – Custom Post Types Events

Part 3 – Integrating iCal with Custom Post Type Events

Part three of this series was a revelation in how to get events to spit out into a format that’s usable by calendars such as Google Calendar, Outlook Cal, or iCalendar. Unfortunately, a few errors were preventing the calendar from working properly for me. Fortunately, like-minded developers gathered in his comments section to try to piece it back together.

My Minor Fixes to Noel Tocks Masterpiece

I compiled those fixes, and included a few of my own into this:

The Calendar fixes included:

  1. Changing the iCal title to pull the site title
  2. Use get_the_excerpt() to grab the excerpt without any markup
  3. Remove the $limit from the Querystr as I wasn’t using this custom meta field. A limit of 500 should suffice, but that can be changed if need be.
  4. Added the appropriate line breaks to ensure the ical file is formatted properly to work with Calendar programs.

When ran on my local machine, my .ICS file looks like this. (Feel free to open it in iCal to test it)

A huge thank you to Noel and the folks in the comments of part 3 for sharing this. It’s going to be a tremendous help in some upcoming event based projects!

Share on:

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">